使用Image Crop Library使用Intent选择后拍摄我的照片
java.lang.IllegalArgumentException:Media是只读的
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
编辑:我也有:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
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;
}
}
如果我删除
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
我得到了
java.lang.SecurityException:Permission Denial:编写com.google.android.apps.photos.content.GooglePhotosImageProvider uri内容://com.google.android.apps.photos.content/0/ HIDDEN < / em>来自pid = HIDDEN ,uid = HIDDEN 需要com.google.android.apps.photos.permission.GOOGLE_PHOTOS或grantUriPermission()