I want to be able to load images dynamically from res/drawable. I don't how many files there will be, but I do know they will be named by convention as "image_N", where N is sequential integer. It is possible that new images will be uploaded while the app is running.
My code is basically
Resources rs = getResources();
String imgName = "android.resource://" + this.getPackageName() + "/drawable/image_" + i;
int imgID = rs.getIdentifier(imgName , null, getPackageName());
if (imgID != 0)
{
Drawable d = rs.getDrawable(imgID);
//etc.
}
but imgID
being returned is always 0
.
I also tried another approach
String imgName = "android.resource://" + this.getPackageName() + "/drawable/image_" + i;
b = BitmapFactory.decodeFile(imgName);
if (b != null)
//etc
But b
is always null
.
I know there are files in the folder with the right names because I put a few there. Not sure what I'm doing wrong. Any help would be greatly appreciated!