problem in opening photoviewer for displaying all the images stored in a particular folder in android

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

  •  24-10-2019
  •  | 
  •  

Question

I have one activity(MyActivity), in which I have a grid view. Also I have the "add existing photo from gallery " button. When we click on this button it will open the gallery viewer application and after selecting any photo in gallery it will update the gridview in MyActivity. Also I am storing the selected photos in the myimage folder in sdcard.

I want that if I will select any particular cell in grid view it will open the photoviewer to display all the images present in that folder (myimage).

The code is given below

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        try {

        Intent intent = new Intent(Intent.ACTION_VIEW);

        intent.setDataAndType(Uri.parse("file:///sdcard/myimage/*"), 
        "image/*"); 

        startActivity(intent); 

}

This code, on clicking particular cell of grid view, opens the photoviewer, but not showing any photos in that folder.

But if I use this code

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        try {

        Intent intent = new Intent(Intent.ACTION_VIEW);

        intent.setDataAndType(Uri.parse("file:///sdcard/myimage/a.jpg"), 
        "image/*"); 

        startActivity(intent); 

}

it is showing only the photo a.jpg, not all the photos in the myimage folder. Also not showing the next and previous arrow in the photoviewer.

I want to display all the images present in a particular folder in sd card with next and previous arrow so, that we can traverse through all the photos.

If this is not possible in this way, suggest me other approach(please attach the code also).

Was it helpful?

Solution

Use the following logic to get path of all images present in gallery. Create your own PhotoGrid to display all images. write separate activity where you have an image view to show the image and next or previous buttons. if you click next button increase the counter set image which is present in that position in ArrayList.

ArrayList<String> listOfAllImages = new ArrayList<String>();
String absolutePathOfImage = null;
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

            String[] projection = { MediaColumns.DATA,
                    MediaColumns.DISPLAY_NAME };

            cursor = activity.managedQuery(uri, projection, null, null, null);
            column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
while (cursor.moveToNext()) {
absolutePathOfImage = cursor.getString(column_index);
listOfAllImages.add(absolutePathOfImage);
}

Thanks Deepak

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