Created
May 7, 2015 14:42
-
-
Save SleeplessByte/58587f9b88ccc59e30d7 to your computer and use it in GitHub Desktop.
Resolve a resource ID for Android
This file contains 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
/** | |
* 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