简体   繁体   中英

Android how to get resource identifier from external storage

I need to get .png image files from external storage located in Downloads folder, with Environment path to /storage/emulated/0/Download/some_image_folder.

I am trying to read files with getResources().getIdentifier() method for External storage, but resource id is not found


//For Internal 
int imageId = getContext().getResources().getIdentifier("image_name", "raw", getContext().getPackageName());

//For External not working
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "image_folder_name";
int imageId = getContext().getResources().getIdentifier("image_name", path , getContext().getPackageName());

So if I am using "raw" folder for internal storage where images are stored, everything works fine.

When I use path for external folder image id cannot be found, it returns 0

Resources are files on your development machine. They are not files on the device, and files on the device are not resources. There is no resource identifier for your file, as it is not a resource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM