How to get corresponding file icon in Android?

后端 未结 3 773
说谎
说谎 2021-02-10 17:21

Every file type associated with its specific icon.

Now if i am choosing somefilename.xxx then how i could be able to choose the icon as

3条回答
  •  广开言路
    2021-02-10 17:32

    Try Using PackageManager.queryIntentActivities:

    final Intent innt = new Intent(Intent.ACTION_VIEW);
    innt.setData(fileUri);
    innt.setType("application/pdf");
    
    final List matches = getPackageManager().queryIntentActivities(innt, 0);
    for (ResolveInfo match : matches) {
        final Drawable icon = match.loadIcon(getPackageManager());
        final CharSequence label = match.loadLabel(getPackageManager());
    }
    

提交回复
热议问题