You just need to format your request correctly:
Instead:
int i = this.getResources().getIdentifier("txt_asecondtext", "strings", this.getPackageName());
Try:
int i = getResources().getIdentifier("[fully qualified package]:drawable/[resource name]", null, null);
So, for Resource "my_image" in the package "com.example" it will look like this:
int i = getResources().getIdentifier("com.example:drawable/my_image", null, null);
UPDATE: I also tested that the following works to change (including the log lines that prove this:
int i = getResources().getIdentifier( getPackageName() + ":drawable/" + resource_name, null, null); Log.d("EXAMPLE", "Just making sure that these IDs match: '" + i + "' == '" + R.drawable.resource_name + "'.");
It can also be formatted, as you did above, and I believe that I pointed out your error: int i = getResources (). getIdentified (resource name, "drawable", getPackageName ());
source share