0

This is the craziest issue. I am loading custom icons from the assets directory for use with my application. The application loads the custom icon and makes a shortcut on the desktop. All of the icons are 48x48 png files.

On the Android 2.1 and 2.2 emulator this works perfect. On the Droid X (Android 2.2) the icons show up smaller than 48x48.

Now for the kicker, if I move one of the icons to the drawable directory and load it from there it shows up correctly.

Any ideas what the problem could be with the droid x?

Is there any way to get a list of all drawables? If there is I could just put all my icons in the drawables directory, albeit a little ugly to dump 100 icons in there.

My code for loading the icons is pretty standard:

        AssetManager assets = context.getAssets();
        InputStream inputStream = assets.open("icons/"+ name);
        if (inputStream != null)
        {
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            if (bitmap != null)
            {
                return bitmap;
            }
        }
Cameron McBride
  • 6,779
  • 11
  • 40
  • 52

2 Answers2

0

See this answer on how to iterate through all drawables in R.

This is the relevant line:

Field[] drawables = android.R.drawable.class.getFields();
Community
  • 1
  • 1
Amir Uval
  • 14,425
  • 4
  • 50
  • 74
0

One thing to mention here is when you said it worked okay on 2.1, 2.2 emulators.. what was the density of the emulators used. Density has a huge impact on how images are displayed.

Another point, according to how android handles images, the attributes of small/normal/large/xlarge screens and ldpi/mdpi/hdpi/xdpi are applied to assets in res and thus drawable folders. It doesnt apply to assets folder.

What I am trying to say is to read up on how Android displays assets and play around with playing your icon in res folder instead of assets folder. You will find the solution, and also increase your Android knowledge.

omermuhammed
  • 7,365
  • 4
  • 27
  • 40
  • To load 100 icons from the res folder I will have to hard code all of them. You can see in my post where I already mention that they could be placed there. I would have to create a class just for creating a list of the icons. Adding or deleting icons in the future would also require changes to the class. I was unable to find any way to get a list of all drawables like you can get a list of assets. – Cameron McBride Feb 15 '11 at 12:53