benkdev
benkdev

Reputation: 673

Get icon of the default application that opens a file

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

Upvotes: 5

Views: 5457

Answers (1)

Sergii Rudchenko
Sergii Rudchenko

Reputation: 5190

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

Something like this:

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());
}

Upvotes: 7

Related Questions