Get the default application icon that opens the file

I have a mime type of a specific file. I want to get the default application icon that opens a file. Therefore, for music, I would display the Winamp icon if it was my default music player. How can i do this?

+5
source share
1 answer

Make an intent with the given mime type and file URI and call PackageManager.queryIntentActivities on it.

Something like that:

final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(fileUri);
intent.setType("image/png");

final List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo match : matches) {
    final Drawable icon = match.loadIcon(getPackageManager());
    final CharSequence label = match.loadLabel(getPackageManager());
}
+7
source

All Articles