开发者

ACTION_SEND sending both an Image and Text in the same Intent

开发者 https://www.devze.com 2023-03-26 04:30 出处:网络
So I would like to do something like: Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myMessageAsImage));

So I would like to do something like:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myMessageAsImage));
intent.putExtra(Intent.EXTRA_TEXT, "My Message");
intent.setType("text/plain"); // or int开发者_StackOverflow中文版ent.setType("image/<imageType>");

However the documentation for ACTION_SEND doesn't seem to make this seem possible. Is there an agreed upon way to do this?


I don't know what you mean by 'common way' but I think you should set the type to intent.setType("image/*");.

EDIT:

How you send data with intent depends on the availability of apps that filter your particular action. Apps that handle ACTION_SEND may not handle ACTION_SEND_MULTIPLE. Clicking Share on HTC Gallery produces a list of applications that handle image, single or multiple. If you choose Mail then you can select multiple images. But if you choose Facebook or Peep then you can only select one image. This is my simple solution if you want to do the reverse of HTC Gallery, that is: user chooses image(s) first then you show him all compatible apps based on how many he selected.

// assuming uris is a list of Uri
Intent intent = null;
if (uris.size > 1){
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else if (uris.size() == 1) {
intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));}
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, "Some message");
startActivity(Intent.createChooser(intent,"compatible apps:"));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号