3

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)));
Subho
  • 539
  • 1
  • 9
  • 25

1 Answers1

6

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • That's means you are telling their is no way to share multiple image with text??? – Subho Jul 10 '16 at 16:22
  • When i am passing this `putStringArrayListExtra()` that time error has gone but text is not shearing. – Subho Jul 10 '16 at 16:31
  • @Subho: As I wrote, apps do not have to support both text and streams with `ACTION_SEND_MULTIPLE`. You may have a bit better luck if you make both `ArrayLists` be the same length. Since your `uriList` has 5 `Uri` values in it, put 5 copies of your string in `extra_text`. But, again, do not expect all apps (or even any apps) to use both the text and the streams. – CommonsWare Jul 10 '16 at 16:40
  • Not a single app is working `ArrayList extra_text = new ArrayList(); for(int i=0;i<5;i++) { uriList.add(pictureUri); extra_text.add(text); }` Text is not shearing with the image.. – Subho Jul 10 '16 at 17:09
  • 1
    @Subho: Temporarily comment out your `shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);` line and see what happens. If your text starts showing up now, you know that the apps that you are testing will only use one or the other extra. – CommonsWare Jul 10 '16 at 17:11
  • Thanks for your suggestion, those app i have in my phone not a single one support multiple text that is why text is not coming with multiple image :) – Subho Jul 10 '16 at 17:37
  • Can you tell me one more thing how to retrive multiple image from other app like gallery app(Moto g3) . This is my menifest intent... ` ` My app is only coming when mre than two image is selected. – Subho Jul 10 '16 at 17:44
  • @Subho: Whatever app you are testing presumably only uses `ACTION_SEND_MULTIPLE` when some threshold is reached. – CommonsWare Jul 10 '16 at 17:50
  • Ya I got the solution i put two intent-filter just like this way ` ` In this your app will coming if you select one or more than one image. – Subho Jul 10 '16 at 17:59