使用.fileprovider在牛轧糖中使用相机捕获图像在裁剪对话框中获取空图像

Capturing image using camera in nougat using .fileprovider getting null image in Crop Dialog box

这是我的代码

MAINIFEST

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

 <provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>

provider_path.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>

这里检查 Naugat 是否这样做

if (haswritePermission == PackageManager.PERMISSION_GRANTED && hasWriteContactsPermission == PackageManager.PERMISSION_GRANTED) {
                ++imageId;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        String imageFilePath = Environment.getExternalStorageDirectory().toString() + "/Images/Profile/profile.jpg";
        File imageFile = new File(imageFilePath);
        imageUri = FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID + ".provider", imageFile);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, PICK_FROM_CAMERA);
    } 
}

onActivityResult

public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

               if (resultCode == RESULT_OK) {
            switch (requestCode) {

                case PICK_FROM_CAMERA:
                    mCropImageView.setImageUriAsync(imageUri);
                    [crop_dialog][1].show();
                    break;

            }
    }
}

裁切图像我正在使用这个库

compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+'

获取这种空图像或空图像

I just change code for Nougat .add separate case for nougat

**for less than M** 

 case PICK_FROM_CAMERA:
                        mCropImageView.setImageUriAsync(imageUri);
                        path=getRealPathFromURI(imageUri);                       
                        Bitmap bitmap=rotateBitmapOrientation(path);
                        mCropImageView.setImageBitmap(bitmap);
                        crop_dialog.show();
                        break;



**for Nougat ** 

case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
                        mCropImageView.setImageUriAsync(imageUri);
                        selectedImage);
                        crop_dialog.show();
                        break;