How Can I Sent Multiple Data Types With Intent.action_send_multiple When Using A Shareintent?
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_STREAM
andEXTRA_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
andimage/jpg
, the intent's type can beimage/jpg
, but if you are sendingimage/jpg
andimage/png
, then the intent's type should beimage/*
.
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?"