3

I use the code below to send an e-mail to may e-mail address. When i click the send button, there's a toast msg saying Message send..., however i don't have it in the code. It must be default. My problem is that this is saying that the message is to be sent but does not say anything about that it was sent. I know it cannot be checked if it arrived, but there should be a msg saying it' s sent. I hope it shows an error when it is not sent, but the users do not know this.

Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"something@gmail.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
        try {
           startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (android.content.ActivityNotFoundException ex) {
           Toast.makeText(About.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }

thanks

erdomester
  • 11,789
  • 32
  • 132
  • 234

2 Answers2

0

This cannot be done. Since any application can respond to the Intent there is no guarantee of any result code or result intent.

See:

Get Mail Sent Notification in onActivityResult "Android"

See:

Trivial: Get confirmation of email sent in android

My own personal tests on ICS are showing both email clients returning 0 for the resultCode regardless of whether the user presses back or send.

Community
  • 1
  • 1
Thomas Dignan
  • 7,052
  • 3
  • 40
  • 48
0

Try this :

protected void onActivityResult(int requestCode, int resultCode, Intent data)

{

    if(requestCode==1)
    {
        if(requestCode==1 && resultCode==Activity.RESULT_OK)    
        {
            Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();


        }
        else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
        {
            Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT).show();


        }
        else 
        {
            Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT).show();

        }

    }   
}
Harjeet Jadeja
  • 1,594
  • 4
  • 19
  • 39
Naveen R
  • 55
  • 1
  • 10