Reputation: 1715
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?
Upvotes: 7
Views: 7225
Reputation: 3188
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
}
}
Upvotes: 16