Question

I am trying to get String path directory to images in the res/drawable and filter through it (jpg, png ..) Something like this

    File folder = new File("/res/drawable");
    images = folder.listFiles(IMAGE_FILTER);
    File image = images[randGen.nextInt(images.length)];

From sd card works easily but couldn't make it from the resource folder! I don't know if this is naive question but I have been trying different options like passing through uri, casting bitmap to File, no luck!

Was it helpful?

Solution

I am trying to get String path directory to images in the res/drawable

Resources are not files on the device. They are entries in the APK's ZIP file. Hence, you cannot construct a File that points to a resource.

You can use AssetManager to list assets, open InputStreams on assets, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top