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

我正在尝试从我的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

回答:

试试这个代码,它对我有用。

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[]{email});

intent.putExtra(Intent.EXTRA_SUBJECT, "Subject here");

intent.putExtra(Intent.EXTRA_TEXT,"Body Here");

if (intent.resolveActivity(getPackageManager()) != null) {

startActivity(intent);

}

还要在android清单中添加意图过滤器。

<activity ...>

<intent-filter>

<action android:name="android.intent.action.SENDTO" />

<data android:scheme="mailto" />

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

以上是 Android Studio mailto Intent不显示主题和邮件正文 的全部内容, 来源链接: utcz.com/qa/412875.html

回到顶部