Possible Duplicates: StartActivityForResults always returns RESULT_CANCELLED for Intent.ACTION_SEND & Show Toast after email send in android?
I'd like to send an E-Mail from within my Android App.
I know you can do this with the following piece of code:
private void sendEmail(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, { "some_email1@gmail.com", "some_email2@gmail.com" });
intent.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
intent.putExtra(Intent.EXTRA_TEXT, "My message");
try{
startActivity(Intent.createChooser(intent, "Send E-Mail"));
}
catch(ActivityNotFoundException ex){
Toast.makeText(this, "There are no E-mail Clients installed on your Device.", Toast.LENGTH_LONG).show();
}
}
What I want to know is whether or not the mail is successfully sent, or that the user has cancelled it (or something else went wrong).
I did try changing:
startActivity(Intent.createChooser(intent, "Send E-Mail"));
to
startActivityForResult(Intent.createChooser(intent, "Send E-Mail"), 123);
And adding the onActivityResult method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
// We come back after the starting Email Activity Client
if(requestCode == 123){
// Mail is successfully send:
if(resultCode == Activity.RESULT_OK){
// Do something
}
else
// Do something else
}
}
}
But Intent.ACTION_SEND
only gives a resultCode of 0 (which equals Activity.RESULT_CANCELED
), no matter if it's successful or not.
So my question is: Does anyone know a way around this, to catch and use the result when using an E-Mail Intent. OR does someone know a completely different (custom) way to send an E-Mail from within an Android App, which enables me to use a result? (WITH code examples provided please.)
Thanks in advance for the responses.
Edit: Made the second part of the question bold, to make clear this isn't a complete duplicate question..