问题描述
我可以帮助我,我试图与多个图像共享文本,但我收到此错误密钥android.intent.extra.TEXT期望ArrayList但值是java.lang.String。返回了默认值。这是我的代码 -
String text =共享文本。 ;
Uri pictureUri = getLocalBitmapUri(shareImg_imvw);
uriList.clear();
for(int i = 0; i< 5; i ++)
{
uriList.add(pictureUri);
}
意图shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType(* / *);
// shareIntent.putExtra(Intent.EXTRA_TEXT,text);
//新代码
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)));
首先, ACTION_SEND
和 ACTION_SEND_MULTIPLE
支持 EXTRA_TEXT
或 EXTRA_STREAM
。应用程序不必同时支持两者。不要指望所有应用都使用它们。
其次, ACTION_SEND_MULTIPLE
要求 EXTRA_TEXT
和 EXTRA_STREAM
是 ArrayList
extras。用 putStringArrayListExtra()
替换 putExtra()
,传入 ArrayList< String>
您想要分享的多个字符串。
HI can anyone please help me i am trying to share text with multiple image but i am getting this error Key android.intent.extra.TEXT expected ArrayList but value was a java.lang.String. The default value was returned.Here is my code-
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)));
First, ACTION_SEND
and ACTION_SEND_MULTIPLE
support either EXTRA_TEXT
or EXTRA_STREAM
. Apps do not have to support both. Do not expect both to be used by all apps.
Second, ACTION_SEND_MULTIPLE
requires that EXTRA_TEXT
and EXTRA_STREAM
be ArrayList
extras. Replace putExtra()
with putStringArrayListExtra()
, passing in an ArrayList<String>
of the multiple strings that you want to share.
这篇关于在android中使用意图共享文本和多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!