6

This code

final ApplicationInfo ai = getPackageManager().getApplicationInfo("com.company.hello", 0);
final Drawable d = getPackageManager().getApplicationIcon(ai);

retreive a 48x48 (mdpi) drawable even on my hidensity HoneyComb device.

Given that I can enlarge the drawable by Bitmap.createScaledBitmap, I'm asking how to extract the hi density icon that is already there. The method getDrawableForDensity is not available for sdk < 15, but I'm not happy to invoke a scaling function for each icon I've to draw when it is available in the package for free.

Edit for bounty

forgetting for a while my device display density the question is the following: given a own package for which we know for sure to have a 72x72 icon in the relative hdpi res folder, how to extract this icon from another package?

THIS FUNCTION is not available on Honeycomb environment.

lorenzoff
  • 1,120
  • 3
  • 15
  • 32
  • What are you using the drawable for once you have it? It seems to me like you could be using the `R.drawable.id` of the image to get it, which will automatically grab the correct one for whatever size screen you are running on currently. – FoamyGuy Jan 16 '13 at 14:13
  • Maybe you are confusing size with density (they are different). You shouldn't be scaling your PNG resources (this is the whole purpose of using different resolution drawables). – Booger Jan 16 '13 at 14:14
  • hi FoamGuy I've already tryed to extract the icon by specific id but the result is the same: 48x48 drawable. Booger: I'm not confusing nothing: given a package, I want the 72x72 drawable that I know been there. My screen density is HI_DENSITY and the solution may be getDrawableForDensity but it is not available. – lorenzoff Jan 16 '13 at 14:17

1 Answers1

1

to find your drawable directlyy with the good density, you have just to try this :

mContext.getResources().getDrawable(R.drawable.mydrawable);

what is the problem? If android get you a 48x48 icon, it's that the good icon or, you haven't set icon in the good res/drawable- folder.

throrin19
  • 17,796
  • 4
  • 32
  • 52
  • Yes, thanks you for your answer but the question is not if 48x48 icon is good or not but how to extract all resolution icons from a package regardless of device density. As I've already written using the API > 15 a function that do exactly what I need is available (getDrawableForDensity) and the question is how to get the same result without using this funcion. – lorenzoff Jan 23 '13 at 10:49