Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACTION_SEND force sending with email

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

like image 776
thepoosh Avatar asked Apr 24 '12 08:04

thepoosh


2 Answers

Try to setType message/rfc822 instead of text/plain

like image 93
Estragon Avatar answered Oct 13 '22 20:10

Estragon


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.

like image 43
user10496632 Avatar answered Oct 13 '22 18:10

user10496632