Carlos P
Carlos P

Reputation: 3989

Android - retrieve the device-appropriate drawable folder as a string

Is it possible to retrieve the correct drawable folder name as a String using Android?

For example, I would like, as a string:

String drawableFolder = someFunction.getFolder();
Log.i("", drawableFolder);

....to output:

XXDPI

.

Usage case: I'm downloading images from a remote URL and would like a mechanism to retrieve a device-appropriate image. It occurred to me I could prepend the URL with the correct name, e.g. http://static.images.server.com/XXDPI_image.png

Upvotes: 0

Views: 65

Answers (1)

Murtaza Khursheed Hussain
Murtaza Khursheed Hussain

Reputation: 15336

You can get the following through device density

int density= getResources().getDisplayMetrics().densityDpi;

switch(density)
{
case DisplayMetrics.DENSITY_LOW:
    Log.d(TAG, "LDPI");
    break;
case DisplayMetrics.DENSITY_MEDIUM:
     Log.d(TAG, "MDPI");
    break;
case DisplayMetrics.DENSITY_HIGH:
    Log.d(TAG, "HDPI");
    break;
case DisplayMetrics.DENSITY_XHIGH:
     Log.d(TAG, "XHDPI");
    break;
}

Upvotes: 1

Related Questions