0

我在通過相機捕獲照片後裁剪照片時遇到棉花糖設備問題。 它在6個以下版本的設備上工作正常。 這裏是我的代碼:通過刪除棉花糖:java.lang.illegalargumentexception:mediaFileUri必須是文件Uri

cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
          mCropImageURI); 

爲紐帶9使用照片而不是畫廊和「照片」應用程序不允許媒體URI

if (requestCode == CAMERA_PICTURE) { 

       Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
       // set data type to be sent , indicate image type and Uri of image 
       cropIntent.setDataAndType(mCapturedImageURI, "image/*"); 
       List<ResolveInfo> list = getPackageManager().queryIntentActivities(cropIntent, 0); 
       int size = list.size(); 
       // handle the case if there's no cropper in the phone 
       if (size == 0) { 
        Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show(); 
        return; 
       } else { 

        //set crop properties 
        cropIntent.putExtra("crop", "true"); 
        //indicate aspect of desired crop 
        cropIntent.putExtra("aspectX", 1); 
        cropIntent.putExtra("aspectY", 1); 
        //indicate output X and Y 
        cropIntent.putExtra("outputX", 256); 
        cropIntent.putExtra("outputY", 256); 

        String fileName = Ut.getDateTimeStamp(); 
        ContentValues values = new ContentValues(); 
        values.put(MediaStore.Images.Media.TITLE, fileName); 

        mCropImageURI = getContentResolver() 
          .insert(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
            values); 

        cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
          mCropImageURI); 

        //retrieve data on return 
        cropIntent.putExtra("return-data", true); 
        //start the activity - we handle returning in onActivityResult 
        startActivityForResult(cropIntent, CROP_PICTURE); 

        return; 
       } 
      } else if (requestCode == CROP_PICTURE) { 
       getCameraPhotoFromIntent(data); 
       setImagePathToSource(); 
      } 
+0

哪個應用是您使用裁剪? – Salmaan

+0

我正在使用「照片」默認應用程序在我的Nexus 9設備中使用裁剪 –

+0

您必須提出問題谷歌,您還可以查看日誌。 – Salmaan

回答

0

我已經自己修復。 所以通過刪除這個,我能夠裁剪圖像。

謝謝。

1

試試這個:

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.MARSHMALLOW) { 
     cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImageURI); 
    }