4

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?

Luke Peterson
  • 8,584
  • 8
  • 45
  • 46
mahdi
  • 16,257
  • 15
  • 52
  • 73

2 Answers2

3

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");
vladaman
  • 3,741
  • 2
  • 29
  • 26
-1
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
        smsIntent.setData(Uri.parse("smsto:"));
        smsIntent.setType("vnd.android-dir/mms-sms");
        smsIntent.putExtra("address", phoneNumber);
        smsIntent.putExtra("sms_body", "body  text"); 
        startActivity(smsIntent);   

phoneNumber - is to whoom you want to send the message.
jettimadhuChowdary
  • 1,058
  • 1
  • 13
  • 23