1

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()

Jonas Borggren
  • 2,591
  • 1
  • 22
  • 40
  • What is the type and the value of `selectedImage`? And why isn't it a local variable of onActivityResult? On which statement do you get the exception? Why do you post so much code? Please post only the code that is used to reproduce the problem. – greenapps Mar 09 '15 at 15:59
  • `Uri selectedImage;` and I get error on this line `tempFile = new File( cursor.getString( columnIndex ) );`. If I knew what part of my code that was causing this I wouldn't be posting it all. – Jonas Borggren Mar 09 '15 at 17:38
  • Split that statement like `String filePath =cursor.getString( columnIndex );`. And tell what filePath is. Then use it for File. You do too much in one statement so difficult to debug. I wonder if new File() would give that exception as it does nothing with the file system. And you dit not tell what selectedImage.getPath() delivers. – greenapps Mar 09 '15 at 17:49
  • `selectedImage.getPath()` gives me the correct path to the file, in this case **/storage/emulated/0/MyPath/img.jpeg** – Jonas Borggren Mar 18 '15 at 10:58
  • That i did ask. But I asked also what filePath was in `String filePath =cursor.getString( columnIndex );` – greenapps Mar 18 '15 at 12:13

0 Answers0