Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for email intent to finish and get result? [duplicate]

In my Android app, I am able to programmatically open up the default email editor with To, Subject, and Message using the following:

Intent emailIntent=new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, toemail);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.setType("text/plain");
emailIntent.setClassName("com.android.email", "com.android.email.activity.MessageCompose");
startActivity(emailIntent);

This works great, but I need to wait in my app until the user finishes with the email screen and also know whether the email was sent or discarded.

Anyone know how to do this?

like image 408
Nicholas Avatar asked Dec 14 '10 19:12

Nicholas


1 Answers

Normally, one could use startActivityForResult() which starts the second activity as a sub-activity. However, in the case of the email activity this doesn't appear to work, likely because of the internal implementation. Try searching before posting questions:

how can we use startActivityforResult() for Email intent?

The actual sending of an email is asynchronous by design, so the activity will likely return before the email is actually sent. I haven't tested this case specifically, but from the above link it seems that the activity returns once the user hits the send button. If this suffices for your use case then super, if you need to know if the email was actually sent you might be SOL.

like image 130
jfelectron Avatar answered Oct 02 '22 21:10

jfelectron