Get resource ID of the icon of another android application

android, icons, resources

Solution

You can get the `Drawable` icon of an app by using:

Drawable icon = getPackageManager().getApplicationIcon( PACKAGE_NAME );

If you are interested in the resource ID of a Drawable of your own app, try this:

int resourceID = getResources().getIdentifier( DRAWABLE_NAME , "drawable", PACKAGE_NAME );

Or, if you care about performance, this version is quicker, but uses reflection:

try {
      Class resource = R.drawable.class;
      Field field = resource.getField( DRAWABLE_NAME );
      int drawableId = field.getInt(null);
    } catch (Exception e) {}

Problem

Is there a way to get the resource ID of the icon of another android app? (ex. `com.android.systemui.R.drawable.ic_xxx`) I tried `context.getApplicationInfo().icon` but it returned a long integer. Is this possible? Thanks

Original source