Send message body and phone number to Viber

mahdi  picture mahdi · Jul 27, 2014 · Viewed 7.8k times · Source

I try to get message and phone number in my app and then send a message to that number, I want to send this message via Viber application. I can send message with this code :

     Intent intent = new Intent(Intent.ACTION_SEND);    
     intent.setType("text/plain"); 
     intent.putExtra(android.content.Intent.EXTRA_TEXT, "test test test"); 
     intent.setpackage("com.viber.voip");
     startActivity(intent);

How can I send phone number to Viber?

Answer

vladaman picture vladaman · Dec 22, 2014

There are two ways to send a message using Intents to Viber.

Option A - will not fill in sms_body unfortunately. But will open directly dialog with specific contact:

Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
smsIntent.setPackage("com.viber.voip");
smsIntent.setData(Uri.parse("sms:+1001002003"));
smsIntent.putExtra("address", "+1001002003");
smsIntent.putExtra("sms_body", "body  text");
startActivity(smsIntent);

Option B - will give you an option which user should receive the message:

Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.viber.voip");
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, "Message body");