I am using code below to get all images from Camera folder inside DCIM and display in my app. But I want to display all images on the device in my app regardless of where they are stored on the device. How can I do this?
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String targetPath = ExternalStorageDirectoryPath + "/DCIM/Camera";
images=new ArrayList<String>();
File targetDirector = new File(targetPath);
File[] files = targetDirector.listFiles();
for (File file : files) {
images.add(file.getAbsolutePath());
}
gallerylist=new CameraGalleryAdapter(getActivity().getApplicationContext(),R.layout.giphy_grid,images);
gridview.setAdapter(gallerylist);
First of all check if required permissions are granted:
Then you have to check if SD card is available:
If SD card is present then use this:
The above code will list all images from SD card, For getting Images from Internal Memory just replace
with
Using the same snippet of code.