Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Toast after email send in android?

I am using the below code to send the mail

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
i.putExtra(Intent.EXTRA_CC, new String[] { bcc_string });
i.putExtra(Intent.EXTRA_SUBJECT, "Video Suggest");
i.putExtra(Intent.EXTRA_TEXT, url_link); 

try {
   startActivityForResult(Intent.createChooser(i, "Send Mail..."), 1);
} catch (android.content.ActivityNotFoundException ex) {
   Toast.makeText(AllVideos.this, "There are no email clients installed.", Toast.LENGTH_SHORT)
   .show();
}

and in my on activity result i am using the following code

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // System.out.println("inactivity");
    // Toast.makeText(AllVideos.this, "Mail Send", 10).show();

    System.out.println("inside activity result");

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

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

But everytime i send or discard the message i get "mail cancelled" toast. Please help me put with this.

Thanks in advance.

like image 777
Shrikant Avatar asked Nov 04 '22 21:11

Shrikant


1 Answers

as per link

You can't, this is not part of the API. It returns once you have pressed send button even if it is not sent

ACTION_SEND does NOT have any output as a result you always get the default value which is RESULT_CANCELED.

Also you can NOT check it with Intent data coming back because it is always null either mail send or discard.

like image 182
Dheeresh Singh Avatar answered Nov 15 '22 00:11

Dheeresh Singh