本文介绍了获取打开文件的默认应用程序的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有特定文件的mime类型.我想获取打开文件的默认应用程序的图标.因此,对于音乐,如果这是我的默认音乐播放器,则将显示Winamp图标.我该怎么办?
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?
推荐答案
使用给定的mime类型和文件URI编写意图,然后调用 PackageManager.queryIntentActivities 上.
Compose an intent with the given mime type and file URI and call PackageManager.queryIntentActivities on it.
类似这样的东西:
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());
}
这篇关于获取打开文件的默认应用程序的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!