0

I want to query all activitys that can play a music file.
I have tried to get all music players like this:

Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setType("audio/*");
packages = getPackageManager().queryIntentActivities(resolve_intent, 0);

if (packages == null || packages.size() <= 0)
{
    //none found
}

but i everytime get an empty (or null) list...
if i do this for type = "image/* or "video/*"
i get all applications that can handle this type.

only for "audio/*" i get no players installed, even if i know that there is one...
so what am i doing wrong?

bricklore
  • 4,125
  • 1
  • 34
  • 62

1 Answers1

0

Fond it myself:

i forgot to set the Data, and i didn't know android uses the data too to resolve the matching intents...

working code:

Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setDataAndType(Uri.fromFile(new File("/some/path/to/a/file")), "audio/*");
List<ResolveInfo> packages = context.getPackageManager().queryIntentActivities(resolve_intent, 0);
Aeris
  • 43
  • 1
  • 7
bricklore
  • 4,125
  • 1
  • 34
  • 62