Does PackageManager.getApplicationIcon () return the default icon?

Is there a way to find out if the Drawable that I get from getApplicationIcon () is the default / inline icon or not?

For example, several applications are installed on my emulator. "Adobe Reader" has an icon provided by Adobe. "com.android.gesture.builder" and "Sample Soft Keyboard", on the other hand, share a common Android icon. getApplicationIcon () for these two packages returned different BitmapDrawable objects, but running getBitmap () on these two objects returned the same Bitmap object ( android.graphics.Bitmap@401a7df8 ).

The only idea I have so far is to do something like How to view R.drawable images. * images and grab all the android.R.drawable resources, create the Pivot data from them and check if the bitmap from getApplicationIcon () returns to any of them. However, this is rather poorly optimized.

Thank!

+5
source share
1 answer

I just figured it out. There is a PackageManager.getDefaultActivityIcon () method that returns Drawable. If this Drawable Bitmap matches the Drawable Bitmap application icon, then this is the default icon.

PackageManager pm = context.getPackageManager();
Drawable icon = pm.getApplicationIcon(apk.package_name);
Drawable default_icon = pm.getDefaultActivityIcon();
if (icon instanceof BitmapDrawable && default_icon instanceof BitmapDrawable) {
    BitmapDrawable icon_bd = (BitmapDrawable)icon;
    Bitmap icon_b = icon_bd.getBitmap();
    BitmapDrawable default_bd = (BitmapDrawable)pm.getDefaultActivityIcon();
    Bitmap default_b = default_bd.getBitmap();
    if (icon_b == default_b) {
        // It the default icon
    }
}
+12
source

All Articles