Open email app programmatically in android for new update

Viewed 5937

How can I open a device email to send an email on the new update of android? it's showing a list of applications with support text/message/html/plain with the following code?

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{context.getString("email_to")});
    intent.putExtra(Intent.EXTRA_SUBJECT, context.getString("email_subject"));
    context.startActivity(Intent.createChooser(intent, context.getString("email_body")));
2 Answers

This Intent will work For Email client with mailto Uri:

try {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"example.yahoo.com"});
    intent.putExtra(Intent.EXTRA_SUBJECT, "App feedback");
    startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
    ToastUtil.showShortToast(getActivity(), "There are no email client installed on your device.");
}

I have found the following code to open the email app programmatically use the following code. I hope this may solve your problem.

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("mailto:"+"email_to"));
intent.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
intent.putExtra(Intent.EXTRA_TEXT, "email_body");
startActivity(intent);
Related