Gallery activity from specific directory

I am working on an Android gallery activity where all the images come from a directory specific to that application. I would like all the images in the directory to be loaded in a manner similar to this.

public Integer[] mThumbIds = {
    R.drawable.ic_launcher_background,R.drawable.ic_launcher_foreground
};

The images are getting saved to an internal directory and I would like to display them as a gallery. How do I get them into the data structure above if they are located here?

File directory = new File("/data/data/com.boredgiant.chora/files"); //path is the string specifying your directory path.
File[] files = directory.listFiles();

Answer

The integers you use are resource identifiers.

You get a File array for your path.

A File instance or a String for a path can not be converted to an interger. And even if you could the integer would be interpreted as resource identifier and your files are not resources.

But no need for an integer.

You can display files very easy using a file path or a File class instance.

Adapt your adapter. Use File array instead of Integer array.

Little work 😉

Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .