0

After reading this question and this question I wrote this code to send an email for multiple addresses:

String[] addresses = {"test@gmail.com", "some@gmail.com" ,"third@gmail.com"};

    Intent someIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto", Arrays.toString(addresses), null)) //all the addresses 
    .putExtra(Intent.EXTRA_SUBJECT, "This is a test")
    .putExtra(Intent.EXTRA_TEXT, "For my app");
    startActivity(Intent.createChooser(someIntent, "Send email..."));

It looks like this:

enter image description here

As you can see in the image for some reason I am getting extra [ for the first email address and extra ] for the last email address (this is causing non-valid email addresses and I can`t send the email).

Why this is happening and how can I remove those extra [ and ].

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53

1 Answers1

0

So as CommonsWare said in his comment, the extra [ and ] are really coming from Arrays.toString().

All I had to do is remove [ and ] from the string and it all worked

String[] addresses = {"1tamir198@gmail.com", "some@gmail.com", "third@gmail.com"};
String cleanAddresses = Arrays.toString(addresses).replace("[", "").replace("]", ""); //remove [] from addresses

    Intent someIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto", cleanAddresses, null)) //all the addresses
            .putExtra(Intent.EXTRA_SUBJECT, "This is a test")
            .putExtra(Intent.EXTRA_TEXT, "For my app");
    startActivity(Intent.createChooser(someIntent, "Send email..."));
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53