3

enter image description hereIntent.EXTRA_TITLE not working when I'm trying to send text and image to other apps like WhatsApp

this is the code I'm trying to

Intent sendIntent = new Intent(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TITLE, Heading);
                sendIntent.setType("image/*");
                sendIntent.putExtra(Intent.EXTRA_STREAM,
                        Uri.parse("file://" + sharefile));
                sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(Intent.createChooser(sendIntent,"Hello"));

when I'm using EXTRA_TEXT it is working fine but for EXTRA_TITLE not working please help me

1 Answers1

1

I'm not sure whether it's clear or not but Intent.EXTRA_TITLE is not meant to send anything to the other app. Instead it gives the activity chooser a title. You could use something like "Which app do you want to open to send this image?".

A working example:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "EXTRA_TEXT");
sendIntent.putExtra(Intent.EXTRA_TITLE, "Heading");
Intent chooserIntent = Intent.createChooser(sendIntent, "Hello");
startActivity(chooserIntent);

Notice: In this case the title will always be "Heading" and not "Hello". If you are using ACTION_SEND this parameter is not used. From Intent.java:

 * @param title Optional title that will be displayed in the chooser,
 * only when the target action is not ACTION_SEND or ACTION_SEND_MULTIPLE.

There are more EXTRAS but I don't know if WhatsApp supports them:

* Optional standard extras, which may be interpreted by some recipients as
* appropriate, are: {@link #EXTRA_EMAIL}, {@link #EXTRA_CC},
* {@link #EXTRA_BCC}, {@link #EXTRA_SUBJECT}.

Edit:

According to this post WhatsApp accepts Intent.EXTRA_STREAM and Intent.EXTRA_TEXT at the same time to show an image caption.

einUsername
  • 1,569
  • 2
  • 15
  • 26
  • thank you sir for your replay.EXTRA_SUBJECT is working on gmail but not in Whatsapp...is there any way to share title and text along with image to the whatsapp – Pantam Ashok Aug 02 '20 at 06:44