Skip to content Skip to sidebar Skip to footer

How Can I Sent Multiple Data Types With Intent.action_send_multiple When Using A Shareintent?

Its pretty clear in the documentation that you can send multiple pieces of data with: Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareI

Solution 1:

If your goal is to share one picture with text, this is the code I would suggest:

Stringtext="Look at my awesome picture";
UripictureUri= Uri.parse("file://my_picture");
IntentshareIntent=newIntent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, pictureUri);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share images..."));

Solution 2:

It's not exactly clear from the question whether you want to send multiple images or just a single image, but with an associated text.

In the first case (multiple images):

Use ACTION_SEND_MULTIPLE and provide the list of uris as EXTRA_STREAM, as in:

IntentshareIntent=newIntent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");

If it's the second case (image plus text):

Use just ACTION_SEND and provide bothEXTRA_STREAMandEXTRA_TEXT, for example:

IntentshareIntent=newIntent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");

If, however, you need to share streams of varying MIME types (such as both pictures and other attachments) just use a more generic MIME type, such as */*. For example:

shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
shareIntent.setType("*/*");

From the documentation of ACTION_SEND_MULTIPLE (emphasis mine):

Multiple types are supported, and receivers should handle mixed types whenever possible. The right way for the receiver to check them is to use the content resolver on each URI. The intent sender should try to put the most concrete mime type in the intent type, but it can fall back to <type>/* or */* as needed.

e.g. if you are sending image/jpg and image/jpg, the intent's type can be image/jpg, but if you are sending image/jpg and image/png, then the intent's type should be image/*.

This works when mixing, say, images and downloaded files.

Post a Comment for "How Can I Sent Multiple Data Types With Intent.action_send_multiple When Using A Shareintent?"