I have a code the fires intent for sending email
Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); i.putExtra(Intent.EXTRA_SUBJECT, subject); i.putExtra(Intent.EXTRA_TEXT, msg); try { startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(Start.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); }
But when this intent is fired I see many item in the list like sms app , gmail app, facebook app and so on.
How can I filter this and enable only gmail app (or maybe just email apps)?
On your computer, open Gmail. See all settings. Click the Accounts and import or Accounts tab. In the "Send mail as" section, click Add another email address.
Use android.content.Intent.ACTION_SENDTO
(new Intent(Intent.ACTION_SENDTO);
) to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.
I wouldn't suggest you get directly to the email app. Let the user choose his favorite email app. Don't constrain him.
If you use ACTION_SENDTO, putExtra does not work to add subject and text to the intent. Use Uri to add the subject and body text.
Intent send = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("[email protected]") + "?subject=" + Uri.encode("the subject") + "&body=" + Uri.encode("the body of the message"); Uri uri = Uri.parse(uriText); send.setData(uri); startActivity(Intent.createChooser(send, "Send mail..."));
The accepted answer doesn't work on the 4.1.2. This should work on all platforms:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto","[email protected]", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT"); startActivity(Intent.createChooser(emailIntent, "Send email..."));
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With