在 android 中以编程方式打开电子邮件应用程序以获取新更新

Sag*_*gar 2 email android

如何打开设备email以发送email关于 android 的新更新?它显示了支持text/message/html/plain以下代码的应用程序列表?

    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")));
Run Code Online (Sandbox Code Playgroud)

ADM*_*ADM 7

此 Intent 将适用于带有 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.");
}
Run Code Online (Sandbox Code Playgroud)


Sag*_*gar 6

我发现以下代码可以使用以下代码以编程方式打开电子邮件应用程序。我希望这可以解决您的问题。

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);
Run Code Online (Sandbox Code Playgroud)