Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Sharing with Subject E-Mail/Whatsapp

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.

like image 227
Christopher Avatar asked Nov 01 '22 09:11

Christopher


1 Answers

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)

like image 82
Vamsi Avatar answered Nov 11 '22 11:11

Vamsi