如果我知道它的包名称,如何从设备上的另一个 Android 应用程序访问图标启动器?
例子
String googlePackageName = "com.google.maps";
Drawable googleIcon = googlePackageName.getIconLauncher() or something.
使用 PackagerManager 的getApplicationIcon () 来完成这个任务:
Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");
我遇到了这个问题。以前从未听说过。但我想这应该是解决方案:
Drawable icon = context.getPackageManager().getApplicationIcon(packageName);
以下剪辑应该为您指明正确的方向:
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;
}