2

I'm looking for a way to open an image with Gallery in Android. So here is what I'm doing: The user click an an image so I launch an intent with its "path":

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, mimeType);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

And gallery opens on the specific image.

My problem is that I can not slide to another picture with Gallery. I have to go back to my application and select the next picture in order to view it.

I already took a look at this: Built-in gallery in specific folder, but it will launch the folder and not the specific picture.

Thank you

Community
  • 1
  • 1
stage
  • 4,225
  • 4
  • 15
  • 8

1 Answers1

0

I was in very similar situation I used Same method as you but instead of setting data like you, I did this way. And Galery opens and I can swipe the pics like you asked

Uri uri = GalleryPreviewButton.getImageContentUri(getContext());
Intent galeryIntent = new Intent(Intent.ACTION_VIEW );
galeryIntent.setDataAndType(uri, "image/*");        
this.startActivity(galeryIntent);

This is the method I used to get Uri from file;

public static Uri getImageContentUri(Context context) {
        String filePath = CURRENT_PATH;
        Cursor cursor = context.getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Images.Media._ID },
                MediaStore.Images.Media.DATA + "=? ",
                new String[] { filePath }, null);
        if (cursor != null && cursor.moveToFirst()) {
            int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
            cursor.close();
            return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
        } else {
            try{
                ContentValues values = new ContentValues();
                values.put(MediaStore.Images.Media.DATA, filePath);
                return context.getContentResolver().insert(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (Exception e){
                return null;
            }
        }
    }