9

every time i create an action for sending an email from my app, it prompts to many options including a QR client...

Is there a way to force sending via email clients only?

Code for sending the email

String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
        "\n\n\nSent from Mojo for Android");
startActivity(i);

Screenshot for what happens when I launch this screenshot

thepoosh
  • 12,497
  • 15
  • 73
  • 132

10 Answers10

27

Try to setType message/rfc822 instead of text/plain

MKJParekh
  • 34,073
  • 11
  • 87
  • 98
Estragon
  • 1,462
  • 11
  • 12
5
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc@xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject of the Mail");
emailIntent.putExtra( android.content.Intent.EXTRA_TEXT,
                           "This is my sample Mail");
emailIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(emailIntent, "Email:"));

else use this it will shows only the mail clients,

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc@xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Subject of the Mail");
emailIntent.putExtra( android.content.Intent.EXTRA_TEXT,
                           "This is my sample Mail");
//emailIntent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(emailIntent, "Email:"));
Aerrow
  • 12,086
  • 10
  • 56
  • 90
4

I think you should change the setType to

i.setType("message/rfc822") ;
MByD
  • 135,866
  • 28
  • 264
  • 277
4

Even though it's too late for @thepoosh, but it may be helpful for future questioners. After a lot of searching and testing, I finally found a good solution. Thanks to the Open source developer, cketti for sharing his/her concise solution.

String mailto = "mailto:bob@example.org" +
    "?cc=" + "alice@example.com" +
    "&subject=" + Uri.encode(subject) +
    "&body=" + Uri.encode(bodyText);

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));

try {
  startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
  //TODO: Handle case where no email app is available
}

This is the link to his/her gist.

user10496632
  • 463
  • 4
  • 13
1

It will show all the available app installed on android phone which can perform sharing or send a link from webview to others. Like - Gmail, facebook, imo, whatsapp, messenger etc.

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String shareLink = webView.getUrl();
intent.putExtra(Intent.EXTRA_TEXT, shareLink);
startActivity(Intent.createChooser(intent, "Share via..."));

But when you force to open mail app only :

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"something@gmail.com"});

try {
    startActivity(Intent.createChooser(intent, "send mail"));
} catch (ActivityNotFoundException ex) {
    Toast.makeText(this, "No mail app found!!!", Toast.LENGTH_SHORT);
} catch (Exception ex) {
    Toast.makeText(this, "Unexpected Error!!!", Toast.LENGTH_SHORT);
}
0

As long as you are using ACTION_SEND with type text/plain, it will show all the valid options. However, if you want, you may design your your own dialog window which shows only Gmail or other mail client by doing filtering programatically.

BTW, why do you even need this window when you just want to use Gmail?

waqaslam
  • 67,549
  • 16
  • 165
  • 178
0
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("mailto:?to=email&subject=hello&body=hello%20world"));
startActivity(Intent.createChooser(intent, "Send via..."));

you can try this:::::

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
0
Intent.setType("plain/text");

At first when I spotted this I immediately though it was a mistake and it was meant to be text/plain, but this is actually the correct way to only display E-mail clients in the application list.

Give it a try and see for yourself.

Elad Nava
  • 7,746
  • 2
  • 41
  • 61
0

intent.setPackage("com.google.android.gm"); //Added Gmail Package to forcefully open Gmail App

Jay Nirmal
  • 380
  • 2
  • 10
-1
String rec[] = { owner.email };
i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822") ;
i.putExtra(android.content.Intent.EXTRA_EMAIL, rec);
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "RE: " + desc);
i.putExtra(android.content.Intent.EXTRA_TEXT,
        "\n\n\nSent from Mojo for Android");
startActivity(i);

try this;:::

Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64