美文网首页
Android 调用系统邮件分享

Android 调用系统邮件分享

作者: 风化成石 | 来源:发表于2021-11-22 15:08 被阅读0次

    项目需求调用系统邮箱分享,发现一般的邮件分享不能满足需求
    Intent.ACTION_SEND 会调起系统的分享面板,并不全是邮箱

    这个代码只会调起邮箱APP:

    public void composeEmail(String[] addresses, String subject) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_EMAIL, addresses);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }
    

    注意两点即可:
    1.使用 ACTION_SENDTO, 而不是 ACTION_SEND.
    2.intent.setData(Uri.parse("mailto:"));//只有邮箱APP被调起

    参照:https://newbedev.com/android-intent-chooser-to-only-show-e-mail-option

    相关文章

      网友评论

          本文标题:Android 调用系统邮件分享

          本文链接:https://www.haomeiwen.com/subject/wmdbtrtx.html