在android中以编程方式打开电子邮件应用程序进行新更新
如何打开设备在android中以编程方式打开电子邮件应用程序进行新更新,android,email,Android,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")});
电子邮件
,在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")));
此意图适用于具有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.");
}
我找到了以下代码,可以使用以下代码以编程方式打开电子邮件应用程序。我希望这能解决你的问题
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);
我们真的需要试一试吗?它不会使应用程序崩溃,是吗?如果找不到处理数据的活动
mailto:
,它会使应用程序崩溃。因此,请始终使用try-catch或使用resloveActivity()
。我遵循了以下代码。但在我的One Plus 3中,电子邮件地址并没有添加到gmail发件人字段中。