Home » Android » android – ACTION_SEND force sending with email

android – ACTION_SEND force sending with email

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&Answers:

Try to setType message/rfc822 instead of text/plain

Answer:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "[email protected]" });
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[] { "[email protected]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:"));

Answer:

I think you should change the setType to

i.setType("message/rfc822") ;

Answer:

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:[email protected]" +
    "?cc=" + "[email protected]" +
    "&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.

Answer:

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[]{"[email protected]"});

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);
}

Answer:

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?

Answer:

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:::::

Answer:

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.

Answer:

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;:::