Get icon resource id of another android app
Is there a way to get the resource id of the icon of another android app? (for example com.android.systemui.R.drawable.ic_xxx
)
I tried context.getApplicationInfo().icon
but returned a long integer. Is it possible?
thank
+1
kevdliu
source
to share
2 answers
You can get the Drawable
app icon using:
Drawable icon = getPackageManager().getApplicationIcon( PACKAGE_NAME );
If you're interested in your own application's Drawable resource id, try this:
int resourceID = getResources().getIdentifier( DRAWABLE_NAME , "drawable", PACKAGE_NAME );
Or, if you care about performance, this version is faster, but uses reflection:
try {
Class resource = R.drawable.class;
Field field = resource.getField( DRAWABLE_NAME );
int drawableId = field.getInt(null);
} catch (Exception e) {}
+5
jenzz
source
to share
This method should work for getting the app icon including yours:
String appPackageName=...; //use getPackageName() in case you wish to use yours
final PackageManager pm=getPackageManager();
final ApplicationInfo applicationInfo=pm.getApplicationInfo(packageName,PackageManager.GET_META_DATA);
final Resources resources=packageManager.getResourcesForApplication(applicationInfo);
final Bitmap appIconBitmap=BitmapFactory.decodeResource(resources,applicationInfo.icon);
0
android developer
source
to share