11

如果我知道它的包名称,如何从设备上的另一个 Android 应用程序访问图标启动器?

例子

String googlePackageName = "com.google.maps";

Drawable googleIcon = googlePackageName.getIconLauncher() or something.
4

3 回答 3

22

使用 PackagerManager 的getApplicationIcon () 来完成这个任务:

Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");
于 2012-11-28T15:54:37.813 回答
2

我遇到了这个问题。以前从未听说过。但我想这应该是解决方案:

Drawable icon = context.getPackageManager().getApplicationIcon(packageName);
于 2012-11-28T16:04:18.363 回答
1

以下剪辑应该为您指明正确的方向:

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;
            }
于 2012-11-28T15:57:35.030 回答