Opening an email client on clicking a button Opening an email client on clicking a button android android

Opening an email client on clicking a button


Goes like this:

Intent intent = new Intent(Intent.ACTION_SEND);intent.setType("plain/text");intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });intent.putExtra(Intent.EXTRA_SUBJECT, "subject");intent.putExtra(Intent.EXTRA_TEXT, "mail body");startActivity(Intent.createChooser(intent, ""));

Alternatively, you could use IntentFactory.getSendEmailIntent(String mailTo, String mailCC,String subject, CharSequence body, File attachment).


To show only email clients use this code:

Intent intent = new Intent(Intent.ACTION_VIEW);Uri data = Uri.parse("mailto:recipient@example.com?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(body));intent.setData(data);startActivity(intent);

If you already chose default email client then it will launch it. Otherwise it will show a list of available email clients.


If you have a e-mail address on screen, you can just use in your xml, like this:

android:autoLink="email"