Uri必须为空或拍摄空白

时间:2017-06-14 19:42:08

标签: android camera

当我按下我的circleimageview时,我试图拍照,拍下照片然后开始上传到firebase,事情是我按下并且相机正确打开但是当我拍照时应用程序崩溃发送给我此错误Failure delivering result ResultInfo{who=null, request=65537, result=-1, data=Intent Uri must be non null or empty

我从这里开始,将imageview设置为onClickListener以启动相机,在ActivityResults方法中,我只需检查权限并保存选择

private Uri  mImageUri = null;

  mProfileImageView = (ImageView) getActivity().findViewById(R.id.profileImageView);
        mProfileImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (ActivityCompat.checkSelfPermission(getActivity(), "android.permission.CAMERA") == PackageManager.PERMISSION_GRANTED &&
                        ActivityCompat.checkSelfPermission(getActivity(), "android.permission.WRITE_EXTERNAL_STORAGE") == PackageManager.PERMISSION_GRANTED) {

                    cameraIntent();

                } else {
                    requestPerms();
                }


            }
        });

        mProgress = new ProgressDialog(getActivity());

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) {

            mImageUri = data.getData();

            CropImage.activity(mImageUri)
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .setAspectRatio(1, 1)
                    .start(getContext(), this);

        }

        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {

            CropImage.ActivityResult result = CropImage.getActivityResult(data);

            if (resultCode == Activity.RESULT_OK) {

                mImageUri = result.getUri();
                mImageBitmap = (Bitmap) data.getExtras().get("data");

                StorageReference filePath = mStorageUsers.child(mImageUri.getLastPathSegment());

                mProgress.setMessage("Estableciendo foto de perfil ...");
                mProgress.show();

                filePath.putFile(mImageUri)
                        .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                                Uri downloadUri = taskSnapshot.getDownloadUrl();

                                mDatabaseUsers.child("profile_picture").setValue(downloadUri.toString());

                                mProfileImageView.setImageBitmap(mImageBitmap);

                                mProgress.dismiss();
                            }
                        })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                mProgress.dismiss();

                                Toast.makeText(getActivity().getApplicationContext(), e.getClass().getSimpleName(), Toast.LENGTH_LONG).show();
                            }
                        });

            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

                Exception error = result.getError();
            }

        }

    }

相机触发器

private void cameraIntent(){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, CAMERA_REQUEST_CODE);
    }

知道为什么会出现这个问题? 这是我的logcat

06-14 16:32:05.126 4783-4783/com.app.myyapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.app.myyapp, PID: 4783
                                                                  java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65537, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.app.myyapp/com.app.myyapp.FragmentMain}: java.lang.IllegalArgumentException: Uri must be non null or empty
                                                                      at android.app.ActivityThread.deliverResults(ActivityThread.java:4094)
                                                                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4137)
                                                                      at android.app.ActivityThread.-wrap20(ActivityThread.java)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                   Caused by: java.lang.IllegalArgumentException: Uri must be non null or empty
                                                                      at com.theartofdev.edmodo.cropper.CropImage.activity(CropImage.java:358)
                                                                      at com.pholy.pholyapp.presentation.feed_user_images.view.PerfilFragment.onActivityResult(PerfilFragment.java:250)
                                                                      at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
                                                                      at android.app.Activity.dispatchActivityResult(Activity.java:6931)
                                                                      at android.app.ActivityThread.deliverResults(ActivityThread.java:4090)
                                                                      at android.app.ActivityThread.handleSendResult(ActivityThread.java:4137) 
                                                                      at android.app.ActivityThread.-wrap20(ActivityThread.java) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:154) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:6123) 
                                                                      at java.lang.reflect.Method.invoke(Native Method)

由于

1 个答案:

答案 0 :(得分:0)

您的问题未显示用于触发MapCAMERA_REQUEST_CODE方案的代码。

假设它是onActivityResult(),则不会通过ACTION_IMAGE_CAPTURE向您提供Uri。代替:

  • 如果您将data.getData()放在EXTRA_OUTPUT ACTION_IMAGE_CAPTURE上,则该图片应位于您指定的位置

  • 否则,您会从Intent

  • 返回Bitmap