Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open gmail in android

Tags:

java

android

I just wanted to open the Gmail app through my app and wanted to set email, subject and message from my application.

I have tried GmailService but it is not supporting bcc or cc emails. Link: https://github.com/yesidlazaro/GmailBackground

BackgroundMail.newBuilder(this)
    .withUsername("[email protected]")
    .withPassword("password12345")
    .withMailto("[email protected]")
    .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();

I would like to use bcc and cc functionality along with the attachment, subject, and message.

like image 225
Faran Tariq Avatar asked Apr 25 '19 06:04

Faran Tariq


2 Answers

// For Email by Any app

Intent email= new Intent(Intent.ACTION_SENDTO);
                email.setData(Uri.parse("mailto:[email protected]"));
                email.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                email.putExtra(Intent.EXTRA_TEXT, "My Email message");
                startActivity(email);
like image 147
Rahul Khatri Avatar answered Sep 29 '22 03:09

Rahul Khatri


open gmail via Intent

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

just pass EXTRA_CC & EXTRA_BCC in intent argument

Edit

Below answer will work on android 11

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject here...");
intent.putExtra(Intent.EXTRA_TEXT,"Your message here...");
startActivity(intent);
like image 24
Priyanka Avatar answered Sep 29 '22 04:09

Priyanka