Intent.EXTRA_EMAIL not populating the To field

前端 未结 6 1657
有刺的猬
有刺的猬 2021-02-03 16:35

I am trying to use an intent to send an email from my application but the To field of the email will not populate. If I add code to fill in the subject or text, they work fine.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 17:07

    Couple of things:

    1 - You need to set the action constant variable as ACTION_SENDTO.
    Intent intentEmail = new Intent(Intent.ACTION_SENDTO);

    2 - If you want it to be opened by only the mail then use the setData() method: intentEmail.setData(Uri.parse("mailto:")); Otherwise it will ask you to open it as text, image, audio file by other apps present on your device.

    3 - You need to pass the email ID string as an array object and not just as a string. String is: "name@email.com". Array Object of the string is: new String[] {"email1", "email2", "more_email"}.

    intentEmail.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@overflow.com", "abcd@stack.com"});
    

提交回复
热议问题