如何在 Android 中打开 Gmail

2024-03-08

我只想通过我的应用程序打开 Gmail 应用程序,并想从我的应用程序设置电子邮件、主题和消息。

我尝试过 GmailService,但它不支持密件抄送或抄送电子邮件。 关联:https://github.com/yesidlazaro/GmailBackground https://github.com/yesidlazaro/GmailBackground

BackgroundMail.newBuilder(this)
    .withUsername("[email protected] /cdn-cgi/l/email-protection")
    .withPassword("password12345")
    .withMailto("[email protected] /cdn-cgi/l/email-protection")
    .withType(BackgroundMail.TYPE_PLAIN)
    .withSubject("this is the subject")
    .withBody("this is the body")
    .withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
        @Override
        public void onSuccess() {
            //do some magic
        }
    }).withOnFailCallback(new BackgroundMail.OnFailCallback() {
        @Override
        public void onFail() {
            //do some magic
        }
    }).send();

我想使用密件抄送和抄送功能以及附件、主题和消息。


通过Intent打开gmail

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("[email protected] /cdn-cgi/l/email-protection"));
intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_CC, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_BCC, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_SUBJECT, "your subject goes here...");
intent.putExtra(Intent.EXTRA_TEXT, "Your message content goes here...");
    
startActivity(intent);

只是通过EXTRA_CC & EXTRA_BCC在意图论证中

Edit

以下答案适用于 Android 11

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected] /cdn-cgi/l/email-protection"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);

Edit 2

val selectorIntent = Intent(Intent.ACTION_SENDTO)
selectorIntent.data = Uri.parse("mailto:")

val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected] /cdn-cgi/l/email-protection"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here...")
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email Body...")
emailIntent.selector = selectorIntent

activity!!.startActivity(Intent.createChooser(emailIntent, "Send email..."))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Android 中打开 Gmail 的相关文章

随机推荐