5

I am using android native sharing with this code:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "I like to share with you some stuff.");
intent.putExtra(Intent.EXTRA_SUBJECT, "I like to share with you.");
intent.setType(CONTENT_TYPE_TEXT);
startActivity(Intent.createChooser(intent, "Share");

When I use E-Mail as the sharing channel, I get what i want:

Subject: I like to share with you.
Text:    I like to share with you some stuff.

When I use WhatsApp as the sharing channel, I get the following text:

I like to share with you.

I like to share with you some stuff.

What do I expect when sharing with Whatsapp:

I like to share with you some stuff.

Is there any option/flag indicating a sharing channel to suppress the subject, if the sharing channel does not support a subject basically.

E.g. E-Mail supports subjects -> Use the provided intent extra. WhatsApp does not support subjects -> Do not use the provided intent extra.

Christopher
  • 9,682
  • 7
  • 47
  • 76

2 Answers2

2

Using queryIntentActivities() method of PackageManager class, you can set the intent extras based on package name.

For more info, check this link: How to filter specific apps for ACTION_SEND intent (and set a different text for each app)

Community
  • 1
  • 1
Vamsi
  • 878
  • 1
  • 8
  • 25
0

With the below code (considering we are using the function in an activity), if the selected app is an Email, it will have a subject otherwise the subject part will not be available for other apps such as messenger, SMS or Text. Body (setText) will be available for all the apps in the same way.

                ShareCompat.IntentBuilder.from(this)
                    .setSubject("I like to share with you.")
                    .setChooserTitle("Share")
                    .setType("text/plain")
                    .setText("I like to share with you some stuff.")
                    .startChooser()
Sagar Patel
  • 506
  • 1
  • 8
  • 23