Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 996
benkdev Avatar asked Nov 23 '11 20:11

benkdev


People also ask

What is the default application for opening text files?

Windows sets Notepad as the default program for opening text files.

How do you change the default opening application?

In File Explorer, right-click on a file whose default program you want to change. Select Open With > Choose Another App. Check the box that says “Always use this app to open . [file extension] files.” If the program you want to use is displayed, select it and click OK.


1 Answers

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());
}
like image 83
Sergii Rudchenko Avatar answered Nov 15 '22 00:11

Sergii Rudchenko