Get Icon from another android Application

前端 未结 3 1149
日久生厌
日久生厌 2021-02-08 04:49

How do I get to the Icon Launcher from another Android application on the device if I know its Package Name?

Example

String googlePackageName = \"com.go         


        
相关标签:
3条回答
  • 2021-02-08 05:13

    Use PackagerManager's getApplicationIcon() for this task:

    Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");
    
    0 讨论(0)
  • 2021-02-08 05:22

    I came across this question. Never heard of before. But I guess this should be the solution:

    Drawable icon = context.getPackageManager().getApplicationIcon(packageName);
    
    0 讨论(0)
  • 2021-02-08 05:26

    The following snipped should point you in the right direction:

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setPackage( packageName );
                final List<ResolveInfo> pkgAppsList = pm.queryIntentActivities( intent, 0 );
                if( pkgAppsList.size() > 0 ) {
                    this.url = pkgAppsList.get(0).activityInfo.name;
                    icon = pkgAppsList.get(0).activityInfo.loadIcon( pm );
                    this.displayName = pkgAppsList.get(0).activityInfo.loadLabel( pm ).toString();
                    this.module = pkgAppsList.get(0).activityInfo.packageName;
                    this.isExternal = true;
                    this.count = count;
                }
    
    0 讨论(0)
提交回复
热议问题