电子邮件意图显示错误的地址

时间:2019-05-14 17:02:39

标签: android android-intent

在阅读this questionthis question之后,我编写了这段代码来发送多个地址的电子邮件:

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..."));

看起来像这样:

enter image description here

如您在图像中看到的,由于某种原因,我在第一个电子邮件地址中得到了额外的[,在最后一个电子邮件地址中得到了额外的](这导致无效的电子邮件地址,无法发送电子邮件。

为什么会这样,我如何删除那些多余的[]

1 个答案:

答案 0 :(得分:0)

因此,正如 CommonsWare 在他的评论中所说,多余的[]确实来自Arrays.toString()

我所要做的就是从字符串中删除[],一切正常

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..."));