2

Is there a way of looping through the default image gallery on an android device? In my app I have managed to pass a selected picture from the default gallery to an imageView by this code:

public void onImageGalleryClicked(View v){
    //Invoke image gallery using implicit intent
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);

    //Where is the image gallery stored
    File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

    //Get path of the image gallery as string
    CurrentPicturePath = pictureDirectory.getPath();

    //Get the URI-representation of the image directory path
    Uri data = Uri.parse(CurrentPicturePath);

    //Set the data and type to get all the images
    photoPickerIntent.setDataAndType(data, "image/*");

    //Invoke activity and wait for result
    startActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST);

}

And showing the picture in in a viewcontroller by:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode == RESULT_OK){
        if(requestCode == IMAGE_GALLERY_REQUEST){
            //Address of the image on SD-card
            Uri imageUri =  data.getData();

            //Declare a stream to read the image from SD-card
            InputStream inputStream;

            try {
                inputStream = getContentResolver().openInputStream(imageUri);

                //Get a bitmap
                Bitmap image = BitmapFactory.decodeStream(inputStream);

                imgPicture.setImageBitmap(image);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
                Toast.makeText(this, "Unable to open image!", Toast.LENGTH_LONG).show();
            }
        }
    }
}

Now I want to have a button in my app that finds the next picture in the default gallery. I'd like a way to loop through the gallery to find my current picture (by path/name!?) to be able to select the next one (or previous)

  • Possible duplicate of [Loading all the images from gallery into the Application in android](http://stackoverflow.com/questions/18590514/loading-all-the-images-from-gallery-into-the-application-in-android) – abbath Sep 21 '16 at 11:12

1 Answers1

0

There are billions of Android devices, spread across thousands of device models. These will have hundreds of different "default image gallery" apps, as those are usually written by device manufacturers. The user does not have to use any of those apps to satisfy your ACTION_PICK request.

There is no requirement of ACTION_PICK implementations to supply you with "next" or "forward" information.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491