I found a way to solve the requirement without getting the resource id.
I’m adding an item to each of my themes with the name of the string:
<item name="themeName">dark</item>
And in the code I check the name like so:
TypedValue outValue = new TypedValue();
getTheme().resolveAttribute(R.attr.themeName, outValue, true);
if ("dark".equals(outValue.string)) {
...
}