Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to retrieve file name and extension of a resource by resource ID

Tags:

java

android

I have the following:

getResources().getResourceEntryName(resourceId);

The problem is, that it retrieves only the file name without the extension.

For example, if I have the following res/drawable/pic.jpg, the

getResources().getResourceEntryName(resourceId);

is returning the value "pic". The extension .jpg is missing.

like image 785
Genry Avatar asked Feb 22 '12 21:02

Genry


1 Answers

To get "res/drawable/pic.jpg" you could use this:

    TypedValue value = new TypedValue();
    getResources().getValue(resourceId, value, true);
    // check value.string if not null - it is not null for drawables...

    Log.d(TAG, "Resource filename:" + value.string.toString());
    // ^^ This would print res/drawable/pic.jpg

Source: android/frameworks/base/core/java/android/content/res/Resources.java

like image 149
Aleksandar Stojiljkovic Avatar answered Sep 20 '22 10:09

Aleksandar Stojiljkovic