【问题标题】:Capturing image using camera in nougat using .fileprovider getting null image in Crop Dialog box在牛轧糖中使用相机捕获图像,使用 .fileprovider 在裁剪对话框中获取空图像
【发布时间】:2017-11-30 19:13:15
【问题描述】:

这是我的代码

主目录

<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.+'

获取此类空图或空图

【问题讨论】:

  • 您似乎从未为imageUri 设置过值。
  • @CommonsWare 。我没有得到。请告诉我这段代码有什么问题?
  • 使用前检查 imageUri==null。
  • Getting this kind of null image or Empty image。你的意思是?请准确。 Null 和empty 是不一样的。告诉我们你得到了什么。
  • mCropImageView.。那是什么?

标签: android image android-fileprovider


【解决方案1】:
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; 

【讨论】:

    猜你喜欢
    • 2020-03-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多