Android - How to open the email client directly

naresh picture naresh · Sep 5, 2012 · Viewed 8.4k times · Source

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

Answer

Vinay W picture Vinay W · Sep 5, 2012

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.