Get icon of the default application that opens a file

狂风中的少年 提交于 2019-12-12 07:37:18

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/8248466/get-icon-of-the-default-application-that-opens-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!