7

I want to open the default email client instead of showing the options. I tried but i am not getting please can anyone help me.

I used the following code:

  final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.setType("text/html");
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Allergy Journal");       
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<small>"+sb.toString()+"</small>"));                                 
        startActivity(Intent.createChooser(emailIntent, "Email:"));   

It's show the options

enter image description here

But I want to open then Default email client directly.

enter image description here

MBMJ
  • 5,323
  • 8
  • 32
  • 51
naresh
  • 10,332
  • 25
  • 81
  • 124

2 Answers2

15

Frame a String in the format String URI="mailto:?subject=" + subject + "&body=" + body;

and

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse(URI);
intent.setData(data);
startActivity(intent);

This will open up the default e-mail program selected by the user.

Linkify does it this way. Check out it's source code, if you like.

Laurent Meyer
  • 2,766
  • 3
  • 33
  • 57
Vinay W
  • 9,912
  • 8
  • 41
  • 47
8

You can used the following code to open whatever intent you want eg gmail, facebook, email etc..Simple in the type as used in my code pass "gmail" if you want to open gmail, pass "face" if u want to open facebook

Intent intent = new Intent(android.content.Intent.ACTION_SEND); 
intent.setType("text/html");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);

if (!resInfo.isEmpty())
{
    for (ResolveInfo info : resInfo) 
    {
    if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type)) 
    {
            intent.putExtra(android.content.Intent.EXTRA_TEXT, htmlBody);
            intent.setPackage(info.activityInfo.packageName);   
            startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_send_text)));
        }
} 
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
  • I want to open android email client. For this what string i used instead of type? – naresh Sep 05 '12 at 06:26
  • Hi, https://stackoverflow.com/questions/42968587/android-email-client-receiver-email-id-empty-in-android-parse @AndroidDev can you please check this . thanks – Faizal Munna Apr 09 '17 at 12:34