Show toast after emailing in android?

I use the code below to send mail

Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_EMAIL, new String[] { " abc@yahoo.com " }); 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 activity result I use 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 every time I send or refuse a message, I get a "canceled mail" toast. Please help me with this.

Thanks in advance.

+4
source share
2 answers

by link

You cannot, this is not part of the API. It returns as soon as you press the submit button, even if it is not sent

ACTION_SEND has no output, as a result, you always get the default value, which is RESULT_CANCELED.

Also, you can NOT check it with returning Intent data, since it is always zero, either send by mail or cancel.

+3
source

Try this way.

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

All Articles