You cannot access file under a package folder. So put them under assets folder like; /src/main/assets/logo/SUB_DIR/FILENAME.png
Then you can access them getContext().getResources().getAssets().open('logo/SUB_DIR/FILENAME.png')
To check if file exists on asset folder use the following code;
private boolean fileExists(String folder, String fileName) {
try {
String[] files = getResources().getAssets().list(folder);
for(String file : files) {
if(file.equals(fileName)) {
return true;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
Call that method as follows
img = (ImageView) findViewById(R.id.imgSDCard);
if(fileExists("logo/sub", "sd_card_enable.png")) {
// asset folder has file
try {
img.setImageDrawable(Drawable.createFromStream(getAssets().open("logo/sub/sd_card_enable.png"), "sd_card_enable.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
Copy your files into the assets folder like following picture;
(logo is a DIR, and sub is a DIR inside logo)
