What is the path directory to res/drawable type String to pass through File(String path) in Android?

StackOverflow https://stackoverflow.com/questions/23139536

Domanda

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!

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top