Intent.EXTRA_EMAIL not populating the To field

前端 未结 6 1654
有刺的猬
有刺的猬 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:10

    Use this

    public void Email(){
        // use this to declare your 'recipient' string and get your email recipient from your string xml file
        Resources res = getResources();
        String recipient = getString(R.string.IntegralEmailAddress);
        Intent emailIntent = new Intent(Intent.ACTION_SEND); 
        emailIntent.setType("message/rfc822");  //set the email recipient
        emailIntent.putExtra(Intent.EXTRA_EMAIL, recipient);
        //let the user choose what email client to use
        startActivity(Intent.createChooser(emailIntent, "Send mail using...")); 
    
    ``}
    

    This will work :)
    This is what android documentation says about Intent.Extra_Email
    -A string array of all "To" recipient email addresses.
    So you should feed string properly You can read more over here
    http://developer.android.com/guide/components/intents-common.html#Email and here http://developer.android.com/guide/topics/resources/string-resource.html Or use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:

    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
    

提交回复
热议问题