Using Image Crop Library to crop my photos after picking them with Intent I get
java.lang.IllegalArgumentException: Media is read-only
Manifest
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
Edit: I also have these:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Code
Intent intent;
if ( Build.VERSION.SDK_INT < 19 ) {
intent = new Intent();
intent.setAction( Intent.ACTION_GET_CONTENT );
intent.putExtra( "android.intent.extra.LOCAL_ONLY", true );
intent.setType( "image/*" );
startActivityForResult( intent, PICK_IMAGE );
} else {
intent = new Intent( Intent.ACTION_OPEN_DOCUMENT );
intent.addCategory( Intent.CATEGORY_OPENABLE );
intent.putExtra( "android.intent.extra.LOCAL_ONLY", true );
intent.setType( "image/*" );
startActivityForResult( intent, PICK_IMAGE );
}
protected void onActivityResult( int requestCode, int resultCode, Intent imageReturnedIntent ) {
super.onActivityResult( requestCode, resultCode, imageReturnedIntent );
switch ( requestCode ) {
case PICK_IMAGE:
try {
selectedImage = imageReturnedIntent.getData();
CropImageIntentBuilder cropImage = new CropImageIntentBuilder( 4, 3, 640, 480, selectedImage );
cropImage.setSourceImage( selectedImage );
startActivityForResult( cropImage.getIntent( this ), CROP_IMAGE );
} catch ( Exception e ) {
e.printStackTrace();
}
break;
case CROP_IMAGE:
try {
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query( selectedImage, filePathColumn, null, null, null );
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex( filePathColumn[ 0 ] );
tempFile = new File( cursor.getString( columnIndex ) );
cursor.close();
} catch ( Exception e ) {
e.printStackTrace();
}
break;
}
}
If I remove
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
I get
java.lang.SecurityException: Permission Denial: writing com.google.android.apps.photos.content.GooglePhotosImageProvider uri content://com.google.android.apps.photos.content/0/HIDDEN from pid=HIDDEN, uid=HIDDEN requires com.google.android.apps.photos.permission.GOOGLE_PHOTOS, or grantUriPermission()