Skip to content

Instantly share code, notes, and snippets.

@SleeplessByte
Created May 7, 2015 14:42
Show Gist options
  • Save SleeplessByte/58587f9b88ccc59e30d7 to your computer and use it in GitHub Desktop.
Save SleeplessByte/58587f9b88ccc59e30d7 to your computer and use it in GitHub Desktop.
Resolve a resource ID for Android
/**
* Resolve id
*
* @param context the context
* @param id the id
* @return the resolved id
*/
public static String resolveId( Context context, int id ) {
StringBuilder out = new StringBuilder();
out.append(" #");
out.append(Integer.toHexString(id));
final Resources r = context.getResources();
try {
String pkgName;
switch (id&0xff000000) {
case 0x7f000000:
pkgName="app";
break;
case 0x01000000:
pkgName="android";
break;
default:
pkgName = r.getResourcePackageName(id);
break;
}
String typeName = r.getResourceTypeName(id);
String entryName = r.getResourceEntryName(id);
out.append(" ");
out.append(pkgName);
out.append(":");
out.append(typeName);
out.append("/");
out.append(entryName);
} catch (Resources.NotFoundException ignore) {
}
return out.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment