Naskov
Naskov

Reputation: 4169

Get Icon from another android Application

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.

Upvotes: 12

Views: 7870

Answers (3)

323go
323go

Reputation: 14274

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;
}

Upvotes: 1

Terril Thomas
Terril Thomas

Reputation: 1506

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

Drawable icon = context.getPackageManager().getApplicationIcon(packageName);

Upvotes: 4

Marcin Orlowski
Marcin Orlowski

Reputation: 75645

Use PackagerManager's getApplicationIcon() for this task:

Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");

Upvotes: 22

Related Questions