Hola everyone,
Been very busy and christmas season on way. Anyway i am here again and have something to show and tell. There was a project i was working on, and i want to send some email message from my app. So i used an intent to open up options of my email clients installed on my device. So its not a big deal to use an intent and i used android.content.Intent.ACTION_SEND and i got the options. But i didn’t just got email clients but also other communication app like text message, dropbox, facebook, twitter etc. That i didn’t want it. I just wanted email clients to show up i.e like email, gmail, hotmail, email text only(or other email client u have installed). After doing research for long hours i came up with 2 solutions. First solution works but not perfect and second solution is just awesome, works perfectly. But first i’l show my code that i used before:

String[] recipients = new String[]{"sendme@me.com", ""};
Intent testIntent = new Intent(android.content.Intent.ACTION_SEND);
testIntent.setType("text/plain");
testIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "blah blah subject");
testIntent.putExtra(android.content.Intent.EXTRA_TEXT, "blah blah body message");
testIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
startActivity(testIntent);

Well the above code doesn’t work if u need just email clients to show but this code shows all communication apps. So i decided to change setType of intent from (“text/plain”) to (“text/email”).

testIntent.setType("text/email");

Well it did filter some apps but still not perfect because it still showed some apps like andFTP, dropbox, google docs etc.
Now i had to do some serious research, i asked in forum but didn’t got much help and then i stumbled into one post that asked similar question on stackoverflow. So i found 2 solution, both works, one is not too perfect but works in most scenario, and second solution is awesomely perfect, well it worked for me so u have to test yourself to see if it works for u 😛

Solution 1:
just change setType to “message/rfc822”. Yes this works but with very minor flaw. It filtered out all communicatio app exept one, i.e andFTP yeah it didn’t filtered out andFTP and this ruined it. But it filtered out others and showed only email clients.

String[] recipients = new String[]{"sendme@me.com", ""};
Intent testIntent = new Intent(android.content.Intent.ACTION_SEND);
testIntent.setType("message/rfc822");
testIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "blah blah subject");
testIntent.putExtra(android.content.Intent.EXTRA_TEXT, "blah blah body message");
testIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
startActivity(testIntent);

Now Solution 2, which worked perfectly for me. here you don’t use android.content.Intent.ACTION_SEND but Intent.ACTION_VIEW

Intent testIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + "blah blah body" + "&to=" + "sendme@me.com");
testIntent.setData(data);
startActivity(testIntent);

filtering non email client programs


Well above code just worked perfectly for me. It filtered out all other communication apps and showed just exclusive email client programs. I hope this works for you also.

Gracias.