0

I am using the following code to share a text to all messaging applications from my application

String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));

By referring:Android: Share plain text using intent (to all messaging apps)

How to set a specific text for Whatsup and another text for other applications?

Community
  • 1
  • 1
salih kallai
  • 879
  • 2
  • 13
  • 34

2 Answers2

0

Try to share with Action.SEND

do this:

Intent myIntentForWhatsapp = new Intent(Intent.ACTION_SEND);
myIntentForWhatsapp.setType("text/plain");
myIntentForWhatsapp.setPackage("com.whatsapp");
myIntentForWhatsapp.putExtra(Intent.EXTRA_TEXT, "Hallo, this is a msg");
try {
    activity.startActivity(myIntentForWhatsapp);
} catch (android.content.ActivityNotFoundException ex) {
    System.out.println("Whatsapp not installed.");
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

If you want to specify the Intent to only open the WhatsApp application then you do the following

PackageManager manager = context.getPackageManager();
try {
    Intent i = manager.getLaunchIntentForPackage("com.whatsapp");
    if (i == null) {
    }
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    context.startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
}
myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33