在Android中使用意图分享文本和多个图像

3

大家好,我希望有人能帮助我解决一个问题。我正在尝试使用多张图片共享文本内容,但是遇到了以下错误:Key android.intent.extra.TEXT expected ArrayList but value was a java.lang.String. The default value was returned. 这是我的代码 -

    String text = "Share text.";
    Uri pictureUri =  getLocalBitmapUri(shareImg_imvw);
    uriList.clear();
    for(int i=0;i<5;i++)
    {
    uriList.add(pictureUri);
    }
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
    shareIntent.setType("*/*");
    //        shareIntent.putExtra(Intent.EXTRA_TEXT, text);
    // new code
    ArrayList<String> extra_text = new ArrayList<String>();
    extra_text.add(text);
    shareIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text);
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(shareIntent, getString(R.string.send_intent_title)));
1个回答

6

首先,ACTION_SENDACTION_SEND_MULTIPLE支持任一EXTRA_TEXT EXTRA_STREAM。应用程序不必同时支持两种方式。不要期望所有应用程序都会同时使用这两种方式。

其次,ACTION_SEND_MULTIPLE需要EXTRA_TEXT EXTRA_STREAMArrayList extras。请用putStringArrayListExtra()替换putExtra(),将包含多个要共享的字符串的ArrayList<String>传递进去。


这意味着您在说没有办法同时分享多张图片和文本吗??? - Subho
当我使用putStringArrayListExtra()传递参数时,错误已经被解决了,但是文本没有分享。 - Subho
1
@Subho:暂时注释掉你的 shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList); 这一行,看看会发生什么。如果你的文本现在开始出现了,那么你就知道你正在测试的应用程序只会使用一个或另一个额外的内容。 - CommonsWare
谢谢您的建议,我手机上的应用程序都不支持多个文本,所以文本没有带多张图片 :) - Subho
是的,我找到了解决方案,就像这样放置了两个意图过滤器: 这样,如果您选择一个或多个图像,您的应用程序将出现。 - Subho
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接