views:

92

answers:

2

I have found various topics here and elsewhere on creating an intent for sending e-mail and that seems to be pretty straightforward. I'm looking for an intent to just launch any e-mail client the user might have.

Here is the code I've seen for sending an e-mail (posted just for reference, this doesn't serve my needs as I don't want to send a new message):

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"[email protected]"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "Subject of the message"); 
i.putExtra(Intent.EXTRA_TEXT   , "Body of the message"); 

Here is the code I put together for specifically launching the Gmail client by package name:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.google.android.gm");
startActivity(intent);

The code above works but isn't flexible in that a user might not be using Gmail but the other built-in e-mail application or a 3rd party e-mail app. I'm looking for an intent that would bring up the chooser in this case so the user can decide which app to launch to read e-mail.

Does anyone know how to accomplish this?

A: 

Does anyone know how to accomplish this?

There is no such Intent -- you can tell this by examining the manifest for the Email application.

The only thing you can do is build yourself a list of email clients you wish to link to and use the PackageManager code you show above for each.

CommonsWare
Thanks, looks like this will be the way I have to go. You'd think this would be a common type of intent that would be included as part of the platform.
afonseca
+1  A: 

Another approach could be Intent.createChooser(); and let the user to choose the right application.

BTW The list could contain not only email applications

Francesco
Thanks for the alternate approach but this won't work in my situation because I don't want the user to have to choose every time.
afonseca