简体   繁体   中英

How to send email and get confirmation in Android

I am trying to send email through intent, and I want to call the API or web service after mail is successfully sent. How can I do that?

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + emailSubject
        + "&body=" + genericText + " " + genericLink);
intent.setData(data);
startActivityForResult(intent, MAIL_CODE);  

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(resultCode == RESULT_OK) {
        // do some task
    }
}

Try This

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(requestCode==1)
    {
        if(requestCode==1 && resultCode==Activity.RESULT_OK)    
        {
            Log.e("Mail sent.", e+"");
        }
        else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
        {
            Log.e("Mail Cancelled.", e+"");
        }
        else 
        {
            Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT).show();
        }
    }   
}

I am trying to send email through intent, and I want to call the API or web service after mail is successfully sent. How can I do that?

You can't.

First, your Intent structure is not a great choice. Use ACTION_SENDTO and the appropriate extras for a mailto: -style request. Do not assume that all email clients will support ACTION_VIEW with your specific URL structure.

Second, neither ACTION_VIEW nor ACTION_SENDTO are designed to work with startActivityForResult() ; their JavaDoc entries indicate that they have no output.

Third, the user does not actually have to send an email. All ACTION_SENDTO does is bring up an email client; what the user does at that point is up to the user, not you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM