companion object {
val TAG: String = "EffectsDescription"
fun fromStringsXml(string: String, context: Context): String {
val ss = string.toLowerCase().replace(" ", "_");
Log.d(TAG, "gonna search for " + ss);
val s = searchForString(ss, context);
Log.d(TAG, "found: " + s);
return s ?: "ERROR"
}
private fun searchForString(message: String, context: Context): String? {
return try {
val resId: Int = context.resources.getIdentifier(message, "string", context.packageName)
Resources.getSystem().getString(resId)
} catch (e: Exception) {
null
}
}
}
and I'm calling from Java like this:
EffectDescription.Companion.fromStringsXml(effectOrCategory, MainActivity.this.getApplicationContext())
but I get ERROR for all variables. I'm logging them just to see if they match strings in my strings.xml and they do. For example I have
Distortion
and it says
gonna search for distortion
found: null