ACTION_SEND在同一个Intent中发送图像和文本

时间:2011-08-03 18:47:06

标签: android

所以我想做点什么:

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 intent.setType("image/<imageType>");

然而,ACTION_SEND的文档似乎并没有使这看起来成为可能。有没有商定的方法来做到这一点?

1 个答案:

答案 0 :(得分:2)

我不知道你的'共同方式'是什么意思,但我认为你应该把类型设置为intent.setType("image/*");

编辑:

如何根据意图发送数据取决于过滤特定操作的应用程序的可用性。处理ACTION_SEND的应用可能无法处理ACTION_SEND_MULTIPLE。单击“在HTC库上共享”可生成处理图像(单个或多个)的应用程序列表。如果选择“邮件”,则可以选择多个图像。但如果您选择Facebook或Peep,那么您只能选择一个图像。这是我的简单解决方案,如果你想要反过来HTC Gallery,即:用户先选择图像,然后根据他选择的数量向他显示所有兼容的应用程序。

// 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:"));