【发布时间】:2012-01-05 02:46:24
【问题描述】:
我有一个特定文件的 mime 类型。我想获取打开文件的默认应用程序的图标。所以对于音乐,如果那是我的默认音乐播放器,我会显示 Winamp 图标。我该怎么做?
【问题讨论】:
标签: android icons mime-types
我有一个特定文件的 mime 类型。我想获取打开文件的默认应用程序的图标。所以对于音乐,如果那是我的默认音乐播放器,我会显示 Winamp 图标。我该怎么做?
【问题讨论】:
标签: android icons mime-types
使用给定的 mime 类型和文件 URI 编写意图,并在其上调用 PackageManager.queryIntentActivities。
类似这样的:
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());
}
【讨论】: