Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open email app programmatically in android for new update

Tags:

android

email

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")));
like image 916
Sagar Avatar asked Sep 11 '25 10:09

Sagar


1 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.");
}
like image 117
ADM Avatar answered Sep 12 '25 23:09

ADM