Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using intent share text with multiple image in android

Tags:

java

android

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)));
like image 477
Subho Avatar asked Nov 18 '25 07:11

Subho


1 Answers

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.

like image 154
CommonsWare Avatar answered Nov 19 '25 21:11

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!