java - Android Studio mailto Intent 不显示主题和邮件正文

标签 java android email android-intent error-handling

我正在尝试从我的 Android 应用程序发送电子邮件。单击按钮后,gmail 应会打开并显示一封新电子邮件,其中包含我之前定义的收件人、主题和电子邮件正文。到目前为止,我已经尝试发送 Intent.ACTION_VIEW 和 Intent.ACTION_SENDTO。两者都只向收件人显示我的草稿。主题和信息都受到压迫。奇怪的是,当使用模拟器时,它工作得很好。还试图锁定 android 错误日志。好像我没有权限。这真的是权限问题还是其他问题? 我真的很感激任何帮助 干杯

这是我的代码:

  • 通过 ACTION_VIEW 发送电子邮件
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:" + to));
intent.putExtra(intent.EXTRA_SUBJECT, subject);
intent.putExtra(intent.EXTRA_TEXT, message);
mainActivity.startActivity(intent);
  • 通过 ACTION_SENDTO 发送电子邮件
Intent email = new Intent(Intent.ACTION_SENDTO);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
mainActivity.startActivity(Intent.createChooser(email, "Choose an Email client :"));
  • 来自 logcat 的错误消息
2019-12-13 01:30:35.172 29268-29268/? E//system/bin/webview_zygote32: failed to make and chown /acct/uid_99044: Permission denied
2019-12-13 01:30:35.172 29268-29268/? E/Zygote: createProcessGroup(99044, 0) failed: Permission denied
2019-12-13 01:30:35.206 29289-29289/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.226 29296-29296/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.355 29268-29268/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Regular.ttf
2019-12-13 01:30:35.356 29268-29268/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Bold.ttf
2019-12-13 01:30:35.356 29268-29268/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:35.356 29268-29268/? E/Typeface: Unable to load Family: null:und-Khmr
2019-12-13 01:30:35.484 29268-29268/? E/Typeface: Error mapping font file /system/fonts/LGAka_Light.ttf
2019-12-13 01:30:35.484 29268-29268/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:35.484 29268-29268/? E/Typeface: Unable to load Family: lg-lgaka:null
2019-12-13 01:30:35.816 29342-29342/? E//system/bin/webview_zygote32: failed to make and chown /acct/uid_99045: Permission denied
2019-12-13 01:30:35.816 29342-29342/? E/Zygote: createProcessGroup(99045, 0) failed: Permission denied
2019-12-13 01:30:35.842 29354-29354/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:35.864 29367-29367/? E/asset: setgid: Operation not permitted
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Regular.ttf
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Error mapping font file /system/fonts/NotoSansKhmer-Bold.ttf
2019-12-13 01:30:36.139 29342-29342/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:36.139 29342-29342/? E/Typeface: Unable to load Family: null:und-Khmr
2019-12-13 01:30:36.362 29342-29342/? E/Typeface: Error mapping font file /system/fonts/LGAka_Light.ttf
2019-12-13 01:30:36.362 29342-29342/? E/Minikin: Could not get cmap table size!
2019-12-13 01:30:36.362 29342-29342/? E/Typeface: Unable to load Family: lg-lgaka:null
2019-12-13 01:30:36.523 4349-4359/? E/GBMv2: FPS Scaler: EXP
2019-12-13 01:30:36.602 29342-29342/? E/WebViewFactory: can't load with relro file; address space not reserved
2019-12-13 01:30:37.058 29220-29220/? E/Gmail: Gmail:EditWebView JS Console: b/119949571:draft.editor.onLoad; source: file:///android_asset/draft_editor_gmail_compiled.js at 89
2019-12-13 01:30:37.146 29220-29220/? E/Gmail: Gmail:EditWebView JS Console: b/119949571:draft.editor.onLoad is finished; source: file:///android_asset/draft_editor_gmail_compiled.js at 90

最佳答案

我想我们遇到了同样的问题。 Android API 29 引入了一些关于向其他应用程序发送数据的改进。在此处查看更多详细信息:Sending simple data to other apps

这是适合我的解决方案。

Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));

final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"address@mail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "The subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "The email body");
emailIntent.setSelector( selectorIntent );

activity.startActivity(Intent.createChooser(emailIntent, "Send email..."));

简而言之,您要求使用 Android 标准应用程序选择器,此外,您指定要发送电子邮件。因此,结果只会出现电子邮件客户端。 如果用户只安装了一个电子邮件客户端, Intent 将立即重定向到它。

希望这对你也有帮助。

关于java - Android Studio mailto Intent 不显示主题和邮件正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314608/

相关文章:

java - Android - ListView 项目样式在滚动时失败

android - 获取插入后的自增值

iphone - 如何在 iPhone 上获取用户的电子邮件地址(经过许可)?

c# - ASP.Net - 通过 IIS 7.5 SMTP 服务器发送 SMTP 邮件

java - "java.lang.ArrayIndexOutOfBoundsException: -1",同时将制表符添加到 "javax.swing.JTabbedPane"

android - 自适应图标显示不正确

java - 如何在 Appium Java 上使用 setClipboardText

java - 使用 Spring 发送电子邮件

java - 使用 JAXB marshal 添加/修改 XML 文件中的元素

java执行命令提示符问题