为了账号安全,请及时绑定邮箱和手机立即绑定

如何在安卓中打开gmail

如何在安卓中打开gmail

jeck猫 2022-10-20 17:21:07
我只是想通过我的应用程序打开 Gmail 应用程序,并想从我的应用程序设置电子邮件、主题和消息。我尝试过 GmailService,但它不支持密件抄送或抄送电子邮件。链接:https ://github.com/yesidlazaro/GmailBackgroundBackgroundMail.newBuilder(this)    .withUsername("username@gmail.com")    .withPassword("password12345")    .withMailto("toemail@gmail.com")    .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();我想将密件抄送和抄送功能与附件、主题和消息一起使用。
查看完整描述

4 回答

?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

// 对于任何应用程序的电子邮件

Intent email= new Intent(Intent.ACTION_SENDTO);
                email.setData(Uri.parse("mailto:your.email@gmail.com"));
                email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                email.putExtra(Intent.EXTRA_TEXT, "My Email message");
                startActivity(email);


查看完整回答
反对 回复 2022-10-20
?
达令说

TA贡献1821条经验 获得超6个赞

通过 Intent 打开 gmail


Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse("abc@gmail.com"));

intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");

intent.putExtra(Intent.EXTRA_CC, new String[]{"xyz@gmail.com"});

intent.putExtra(Intent.EXTRA_BCC, new String[]{"pqr@gmail.com"});

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


编辑


以下答案适用于android 11


Intent intent = new Intent(Intent.ACTION_SENDTO);

intent.setData(Uri.parse("mailto:"));

intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"abc@gmail.com"});

intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");

intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");

startActivity(intent);

编辑 2


val selectorIntent = Intent(Intent.ACTION_SENDTO)

selectorIntent.data = Uri.parse("mailto:")


val emailIntent = Intent(Intent.ACTION_SEND)

emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("recipient@mail.com"))

emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here...")

emailIntent.putExtra(Intent.EXTRA_TEXT, "Email Body...")

emailIntent.selector = selectorIntent


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


查看完整回答
反对 回复 2022-10-20
?
慕哥6287543

TA贡献1831条经验 获得超10个赞

// 这是用于 Gmail 应用程序的

Intent email= new Intent(Intent.ACTION_VIEW);
            email.setType("message/rfc822")
            .setData(Uri.parse("mailto:your.email@gmail.com"))
            .putExtra(Intent.EXTRA_EMAIL, "your.email@gmail.com")
            .putExtra(Intent.EXTRA_SUBJECT, "Subject")
            .putExtra(Intent.EXTRA_TEXT, "My Email message")
            .setPackage("com.google.android.gm");
            startActivity(email);


查看完整回答
反对 回复 2022-10-20
?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

//这是用gmail打开的

Intent i = new Intent(Intent.ACTION_SENDTO);
            i.setType("text/plain");
            i.setData(Uri.parse("mailto:"));
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@gmail.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "Mail Subject");
            i.putExtra(Intent.EXTRA_TEXT   , "massage");
            i.setPackage("com.google.android.gm");            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(AnotherActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }



查看完整回答
反对 回复 2022-10-20
  • 4 回答
  • 0 关注
  • 115 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信