I’m currently developping an application in which I can send SMS and email.
No big deal, that’s quite easy to do.
Here is how I send the SMS:
private void sendSms() {
Log.i("", "SEND SMS");
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("sms:123456789"));
intent.putExtra("sms_body", "My message");
startActivity( intent );
}
Here is my code to send an email:
private void sendEmail() {
Log.i("", "SEND");
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, "address@fuu.com");
email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
email.putExtra(Intent.EXTRA_TEXT, "My body email");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Send an email:"));
}
Independently, those work great.
But I want to send my email once my SMS is sent or canceled.
I can’t find how I can get back the close event of the SMS intent/activity to send the email.
Any idea ?
You should use the startActivityForResult when starting this kind of activities.
You can then get the result of the started activity by implementing the onActivityResult method
The flow will be something like the following
You can do the same thing for the send email activity.
If you are interested on knowing what the child activity result was (ie: send sms cancelled or actually sent), you can use the onActivityResult resultCode parameter.