1

I want to create an IntentChooser who offer to share text only via SMS or WhatsApp.

Here is my code to share via WhatsApp:

Intent localIntent = new Intent(Intent.ACTION_SEND);
localIntent.setType("text/plain");
localIntent.setPackage("com.whatsapp");
if (localIntent != null) {
    localIntent.putExtra(Intent.EXTRA_TEXT, "Hi there! I'm using this app");
    startActivity(Intent.createChooser(localIntent, "Hi there! I'm using this app"); 
}

I need to add to this also sharing with SMS. How can I do it?

thepurpleowl
  • 147
  • 4
  • 15
offset
  • 1,407
  • 1
  • 16
  • 34

1 Answers1

1

use this for Whatsapp.

            try {
                startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").setPackage("com.whatsapp").putExtra(Intent.EXTRA_TEXT, Message));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(this, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
            }

and this for SMS .

         String number = "12346556";  // The number on which you want to send SMS  
         startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));

OR

Possibly Duplicate of Multiple IntentChooser

Community
  • 1
  • 1
sushildlh
  • 8,986
  • 4
  • 33
  • 77