I would like to get the ID of the referenced resource in runtime. For example this is my code:
<string name="d2c_entryroadblock_start_value" translatable="false">@string/get_started</string>
and I am interested in the ID of the R.string.get_started having only the reference to R.string.d2c_entryroadblock_start_value in runtime.
You can also see how it looks in the APK analyzer below - I need to get that @ref/0x7f1302fc

You can get that with the Resources#getValue() method, passing false for the resolveRefs parameter. For example:
TypedValue value = new TypedValue();
getResources().getValue(R.string.alias_name, value, false);
int aliasedId = value.data;
As shown, the numerical ID for the aliased resource will be in the TypedValue's data field. If you actually need it in hexadecimal, you can pass it to Integer.toHexString(). And, if you need the aliased resource name, then it's simply:
String aliasedName = getResources().getResourceEntryName(value.data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With