0

i've got a mess about email intent in Android 4.1.1. here my code:

emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, "email@gmail.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "text");

But dialog just showed Bluetooth and Messages app. how can i show email app as in gmail in dialog? Can anyone help me, thanks so much!

  • that works for me http://stackoverflow.com/a/2197841/3626214 Check it, use `.setType("message/rfc822")` instead `text/plain` – Aspicas Oct 20 '15 at 10:27
  • I've already found the reason that i met this wrong things. The reason was u have to set up applications included mail feature in its. I forgot set up one of them. So i've got this mess. thanks everyone helped me ! – Lộc Nguyễn Oct 27 '15 at 03:19

4 Answers4

3
    Intent emailIntent;

    emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setData(Uri.parse("mailto:email@gmail.com"));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "text");

    if (emailIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(emailIntent);
    } else {
        //not_found_email_apps;
    }
Hasanaga
  • 1,099
  • 1
  • 9
  • 19
1
protected void sendEmail() {
  Log.i("Send email", "");
  String[] TO = {""};
  String[] CC = {""};
  Intent emailIntent = new Intent(Intent.ACTION_SEND);

  emailIntent.setData(Uri.parse("mailto:"));
  emailIntent.setType("text/plain");
  emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
  emailIntent.putExtra(Intent.EXTRA_CC, CC);
  emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
  emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

  try {
     startActivity(Intent.createChooser(emailIntent, "Send mail..."));
     finish();
     Log.i("Finished sending email...", "");
  }
  catch (android.content.ActivityNotFoundException ex) {
     Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
  }
Karthick
  • 584
  • 4
  • 25
0

Above code should work for your query but it's look like you are testing it on Emulator, if you testing it on that than make sure any email client should be present for sending email, for ex. inbuilt Gmail client on mobile phone.

Mayur R. Amipara
  • 1,223
  • 1
  • 11
  • 32
0

I've already found the reason that i met this wrong things. The reason was u have to set up applications included mail feature in its. I forgot set up one of them. So i've got this mess. thanks everyone helped me !