Created
April 29, 2014 19:42
-
-
Save rnewman/f7f0d6740f9a2ee5a613 to your computer and use it in GitHub Desktop.
How to get the label for a resource ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package android.content.res; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
public class AssetManagerSnooper { | |
/** | |
* Use reflection to find the resource name for the given ID. | |
*/ | |
public static final String getNameForID(AssetManager assets, int id) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { | |
Method method = AssetManager.class.getDeclaredMethod("getResourceName", int.class); | |
method.setAccessible(true); | |
return (String) method.invoke(assets, id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment