英文:
Open Email using Android Intent
问题
我正在使用以下代码通过电子邮件意图发送我的应用程序反馈。在版本28之前,它正常工作。但是在Android 29中,当打开电子邮件应用程序时,我没有获取到主题和正文文本,只显示了电子邮件地址,没有其他文本。我的代码如下:
String appName = getResources().getString(R.string.app_name);
int versionCode = BuildConfig.VERSION_CODE;
String versionName = BuildConfig.VERSION_NAME;
String deviceInfo = "设备信息:";
deviceInfo += "\n 系统版本:" + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
deviceInfo += "\n 系统API级别:" + android.os.Build.VERSION.SDK_INT;
deviceInfo += "\n 设备:" + android.os.Build.DEVICE;
deviceInfo += "\n 型号(和产品):" + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")";
deviceInfo += "\n 应用版本代码:" + versionCode;
deviceInfo += "\n 应用版本名称:" + versionName;
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "myemail@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, appName + " 问题");
emailIntent.putExtra(Intent.EXTRA_TEXT, "在此处编写您的问题 \n\n\n______________________________\n\n" + deviceInfo);
startActivity(Intent.createChooser(emailIntent, "发送邮件..."));
在Logcat中我没有看到任何错误。如果有人可以帮助我解决这个问题,请告诉我。谢谢!
英文:
I am using below codes for send feedback of my application via email intent. It was working fine till build version 28. But in Android 29, I am not getting subject and body text include during open the email app, its showing to email address only not other text. My code is like below
String appName = getResources().getString(R.string.app_name);
int versionCode = BuildConfig.VERSION_CODE;
String versionName = BuildConfig.VERSION_NAME;
String deviceInfo = "Device Info:";
deviceInfo += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
deviceInfo += "\n OS API Level: " + android.os.Build.VERSION.SDK_INT;
deviceInfo += "\n Device: " + android.os.Build.DEVICE;
deviceInfo += "\n Model (and Product): " + android.os.Build.MODEL + " (" + android.os.Build.PRODUCT + ")";
deviceInfo += "\n App Version Code: " + versionCode;
deviceInfo += "\n App Version Name: " + versionName;
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "myemail@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, appName + " Problem");
emailIntent.putExtra(Intent.EXTRA_TEXT, "write your issue here \n\n\n______________________________\n\n" + deviceInfo);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
I am not getting any error in logcat. Let me know if anyone can help me for solve the issue.
Thanks!
答案1
得分: 1
我建议将所有内容放在意图数据中,像这样:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String mailTo = "mailto:example@example.com" +
"?cc=" + "" +
"&subject=" + Uri.encode("邮件主题") +
"&body=" + Uri.encode("邮件正文");
emailIntent.setData(Uri.parse(mailTo));
// 对于结果
startActivityForResult(Intent.createChooser(emailIntent, "发送邮件"), 100);
// 无结果
startActivity(Intent.createChooser(emailIntent, "发送邮件"));
它运行良好,大多数(如果不是所有)电子邮件客户端都应该能够识别这个。
英文:
I would recommend putting everything in the intent data like this
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String mailTo = "mailto:example@example.com" +
"?cc=" + "" +
"&subject=" + Uri.encode("Email subject") +
"&body=" + Uri.encode("Email body");
emailIntent.setData(Uri.parse(mailTo));
// For result
startActivityForResult(Intent.createChooser(emailIntent, "Send email"), 100);
// Without result
startActivity(Intent.createChooser(emailIntent, "Send email"));
It works fine and most, if not all email clients should pick that up.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论