java - 我正在尝试在不打开选择器的情况下向多个人发送电子邮件,这可能吗?
问题描述
我正在尝试在不打开选择器的情况下向多个人发送电子邮件,这可能吗?
我尝试使用数组,但它给了我一个错误。
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("example@gmail.com") +
"?subject=" + Uri.encode("the subject") +
"&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send Email..."))
解决方案
向多个用户发送电子邮件的正确方法是:
科特林:
private fun emailToMultipleUser() {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.setPackage("com.google.android.gm")
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("example@gmail.com","chand@gmail.com"))
intent.putExtra(Intent.EXTRA_SUBJECT, "email subject")
intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...")
try {
startActivity(Intent.createChooser(intent, "send mail"))
} catch (ex: ActivityNotFoundException) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT)
} catch (ex: Exception) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT)
}
}
爪哇:
private void emailToMultipleUser() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType( "text/plain");
intent.setPackage("com.google.android.gm");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"example@gmail.com","chand@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "email subject");
intent.putExtra(Intent.EXTRA_TEXT, "Hi All ...");
try {
startActivity(Intent.createChooser(intent, "send mail"));
} catch (ActivityNotFoundException ex) {
Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
} catch (Exception ex) {
Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
}
}
推荐阅读
- algorithm - 如果存在某些东西,查找的最佳数据结构是什么?
- php - php:如何在 mysqli 中获取多个表
- git - 提供从机器访问 Github 私有仓库的权限
- javascript - Jquery中的本地存储和表单
- python - Django:如何在一个模板中使用超过 2 个基于类的通用视图
- python - 如何使用另一个类连接和断开 matplotlib 的事件处理程序?
- java - 为什么在一次完整 gc 后提升和幸存者内存大小会增加
- python - 如何从主机浏览器访问 Virtualbox Python Flask 服务?
- sql - 从另一个选择中选择填充缺失值的 SQL 查询
- python - 傅里叶如何变换一个 1 和 0 的数组