12

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.google.maps";

Drawable googleIcon = googlePackageName.getIconLauncher() or something.
saluce
  • 13,035
  • 3
  • 50
  • 67
Naskov
  • 4,121
  • 5
  • 38
  • 62

3 Answers3

22

Use PackagerManager's getApplicationIcon() for this task:

Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Can you please expand your answer? Write the exact line code. Please. – Naskov Nov 28 '12 at 15:56
  • Interestingly this does not work in Compose. val drawable = packageManager.getApplicationIcon(app.packageName) Icon( drawable.toBitmap(config = Bitmap.Config.ARGB_8888).asImageBitmap() , contentDescription = "Icon", modifier = Modifier .padding(8.dp), tint = MaterialTheme.colorScheme.secondary ) it gives a round filled circle. – Mehdi Haghgoo Apr 02 '23 at 20:36
3

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

Drawable icon = context.getPackageManager().getApplicationIcon(packageName);
Terril Thomas
  • 1,486
  • 13
  • 32
1

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;
}
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
323go
  • 14,143
  • 6
  • 33
  • 41