【问题标题】:marshmallow : java.lang.illegalargumentexception: mediaFileUri must be a File Uri棉花糖:java.lang.illegalargumentexception:mediaFileUri 必须是文件 Uri
【发布时间】:2016-03-10 10:34:55
【问题描述】:

在通过相机拍摄照片后裁剪照片时,我在棉花糖设备中遇到问题。 它在 6 版本以下的设备上运行良好。 这是我的代码:

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

【问题讨论】:

  • 您使用哪个应用进行裁剪?
  • 我正在使用“照片”默认应用在我的 Nexus 9 设备中使用裁剪
  • 你必须向谷歌提出问题,你也可以查看日志。
  • 是的,我注意到,“照片”应用程序正在崩溃,而不是我正在运行的应用程序。你能解释一下这个错误“mediaFileUri must be a File Uri”

标签: android android-camera android-6.0-marshmallow android-camera-intent illegalargumentexception


【解决方案1】:

试试这个:

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

【讨论】:

    【解决方案2】:

    我已经通过删除自己修复了

    cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                mCropImageURI);
    

    因为 nexus 9 使用照片而不是图库,并且“照片”应用不允许使用媒体 URI。 因此,通过删除它,我可以裁剪图像。

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2017-02-02
      • 2018-09-08
      • 2016-03-15
      • 1970-01-01
      • 2017-05-12
      • 2019-01-29
      相关资源
      最近更新 更多