2

I'm writing an Android app that emails reports to the user. I've seen apps that launch a list of other installed apps that can be used to send email and I am wondering how to do that.

I've looked at this code and this question.

How would you filter out from the list of installed apps to know which ones are used for email?

Community
  • 1
  • 1
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106

2 Answers2

5

You should be able use a similar pattern to the one shown in the answer in your second link. You just need to change the intent:

final Intent sendIntent = new Intent(Intent.ACTION_SEND, null);
final List<ResolveInfo> pkgAppsList
    = context.getPackageManager().queryIntentActivities(sendIntent, 0);
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • So the intent filters out the non-email applications? – Kristy Welsh May 10 '13 at 17:39
  • 1
    @KristyWelsh - This will return a list of information about the app packages that can send email (or, more precisely, those apps that claim to be able to handle an `ACTION_SEND` intent, which is supposed to be for email). It's simply a way of asking the framework to do the filtering for you and return the results. – Ted Hopp May 10 '13 at 17:44
  • 1
    Most importantly, this will return a list of `Activity`s that have `IntentFilter`s on `Intent.ACTION_SEND`. However, if you simply call `startActivity` with this `sendIntent`, and there are more than one `Activity`s that can handle `sendIntent, Android will use the user's chosen default app (for `Intent.ACTION_SEND`) OR present them with the option to select the app to use. So, you really don't need get this list (unless you are going manually present the list / need to know if there is at least one email app), as Android will take care of picking the app to choose automatically. – Steven Byle May 10 '13 at 17:56
  • @Steven Byle - So really, the second answer is the one I should choose as correct? – Kristy Welsh May 10 '13 at 18:00
  • 1
    @KristyWelsh you asked "How would you filter out from the list of installed apps to know which ones are used for email?". This answers your question precisely (I would accept this one). However, what I was noting is that you may not need to do what you were originally asking for. – Steven Byle May 10 '13 at 18:14
2

You might try this code from this answer:

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"xxxxxxxx@gmail.com"});
    emailIntent.setType("plain/text");
    startActivity(Intent.createChooser(emailIntent, "Send email..."));
Community
  • 1
  • 1
antlersoft
  • 14,636
  • 4
  • 35
  • 55
  • I can launch the activity. I am just looking for a way to filter out non-email installed applications from the applications list. – Kristy Welsh May 10 '13 at 17:38