Skip to content

Instantly share code, notes, and snippets.

@rnewman
Created April 29, 2014 19:42
Show Gist options
  • Save rnewman/f7f0d6740f9a2ee5a613 to your computer and use it in GitHub Desktop.
Save rnewman/f7f0d6740f9a2ee5a613 to your computer and use it in GitHub Desktop.
How to get the label for a resource ID
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