I\'m using Intent.ACTION_SEND
to send an email. However, when I call the intent
it is showing choices to send a message, send an email, and also to
@Ganapathy:try this code for display gmail
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "jckdsilva@gmail.com" });
gmail.setData(Uri.parse("jckdsilva@gmail.com"));
gmail.putExtra(Intent.EXTRA_SUBJECT, "enter something");
gmail.setType("plain/text");
gmail.putExtra(Intent.EXTRA_TEXT, "hi android jack!");
startActivity(gmail);
Intent email = new Intent(android.content.Intent.ACTION_SEND);
email.setType("application/octet-stream");
EDIT:
You could try setting type to "message/rfc822"
as well.
try this....
I notice, that this is an pretty old question but it is the first result when searching for a "Send mail" solution and all answers have a common problem:
Using Intent.ACTION_SEND
and intent.setType("message/rfc822")
will result in a chooser that not only shows mail apps but all apps that can handle any MIME type support by message/rfc822, e.g. .mhtml
, .mht
, .mime
. Beside mail apps this could be Google Drive, Dropbox, Evernote, etc.
The only solution I found to limit the chooser to mail apps only is to use Intent.ACTION_SENDTO instead:
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto","address@example.com", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "My Mail");
intent.putExtra(Intent.EXTRA_TEXT , "My Message");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
I had a similar problem with my app. I recently found this link form the official android developers site that really helps! Common Intents: Email
TL;DR:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
Now, you will only be shown email clients!
You can add a Subject and Body by doing this:
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Body" );
Using message/rfc822
type as pointed here: ACTION_SEND force sending with email solves the issue.
try with ACTION_VIEW not ACTION_SENDTO , ACTION_VIEW will makes system calls only to Email Apps
Intent emailIntent = new Intent(Intent.ACTION_VIEW);