Java tutorial
//package com.java2s; import android.content.ClipData; import android.content.Intent; import android.net.Uri; import android.provider.MediaStore; public class Main { public static Intent getPhotoGalleryIntent(Uri photoUri) { Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); addPhotoPickerExtras(galleryIntent, photoUri); return galleryIntent; } private static void addPhotoPickerExtras(Intent intent, Uri photoUri) { intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setClipData(ClipData.newRawUri(MediaStore.EXTRA_OUTPUT, photoUri)); } }