【问题标题】:Get icon of the default application that opens a file获取打开文件的默认应用程序的图标
【发布时间】:2012-01-05 02:46:24
【问题描述】:

我有一个特定文件的 mime 类型。我想获取打开文件的默认应用程序的图标。所以对于音乐,如果那是我的默认音乐播放器,我会显示 Winamp 图标。我该怎么做?

【问题讨论】:

    标签: android icons mime-types


    【解决方案1】:

    使用给定的 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());
    }
    

    【讨论】:

    • 因为放假没去上班,所以周一回帖,谢谢!
    • 这可以获取默认图标。在我的应用程序中显示时,图标可绘制对象周围的填充是不同的。我将它们显示在一个列表中,所以现在我必须弄清楚如何获得统一的填充。
    猜你喜欢
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-31
    相关资源
    最近更新 更多