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.
source share