0

I have multiple posts about sending an email and even in the Android documentations. IT does not seem to work. I want to basically to allow the user to choose their email programs to send an email. Here is the code

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("*/*");
                emailIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"xyz@gmail.com"});
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                emailIntent.putExtra(Intent.EXTRA_TEXT   , "msg");
                startActivity(Intent.createChooser(emailIntent, "Send mail..."));

However it does nothing (ie no activity)

What is it that I am doing wrong? If I use Action.Send then it display all social medial platforms including facebook and whatsapp ..etc

Thank you

Snake
  • 14,228
  • 27
  • 117
  • 250

1 Answers1

0

This is taken from Adroid developers site and combining with this question:

public void composeEmail(String[] addresses, String subject, String msessage) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("application/octet-stream");
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, message);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

Note I made a few changes to match the case of the question.

Juan
  • 5,525
  • 2
  • 15
  • 26
  • It is showing other non email programs such as whatsapp, bluetooth, slack ..etc – Snake Dec 13 '18 at 04:29
  • Based on the same question, ste type to: application/octet-stream. I'll change it in the answer. Though I am not sure if it will work correclty as EXTRA_STREAM is no being set. – Juan Dec 13 '18 at 04:32