Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email using GMail in android

Tags:

java

android

I am trying to open email sending form of Gmail directly on button click but this always shows a list of options for sending email.

I am doing this for opening GMail form:

            Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND);
            String[] recipients = new String[]{"" , "" ,};
            emailIntent.putExtra( android.content.Intent.EXTRA_EMAIL, recipients);
            emailIntent.putExtra( android.content.Intent.EXTRA_SUBJECT, "This is my text" );
            emailIntent.putExtra( android.content.Intent.EXTRA_TEXT, "");
            emailIntent.setType("message/rfc822");
            startActivity( Intent.createChooser(emailIntent, "Send Email" ));

but this is not opening GMail form. What can i do for opening GMail form please help.

Is there any way to do this?

like image 721
Pari Avatar asked Mar 14 '12 18:03

Pari


People also ask

Why can't I send Gmail from my Android phone?

Clear Cache and Data for Gmail Sometimes residual cache files get corrupted and cause the app to malfunction. When you are experiencing the problem of Gmail not sending emails on Android, you can always try clearing the cache and data for the app.

How do I send an email to multiple recipients in Gmail mobile?

Step 1: Open your Gmail account. Step 2: Click on the Compose box to type the email you would like to send to multiple recipients from your Gmail. Step 3: After writing the email, click on the BCC option besides the CC option.

Why is my Gmail on my phone not sending?

Open the Gmail app . Settings. Tap your account. Make sure the box next to "Sync Gmail" is checked.


1 Answers

use something on the lines

public void sendGmail(Activity activity, String subject, String text) {
    Intent gmailIntent = new Intent();
    gmailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    try {
      activity.startActivity(gmailIntent);
    } catch(ActivityNotFoundException ex) {
      // handle error
    }
}
like image 113
mkso Avatar answered Oct 29 '22 08:10

mkso