Android 7.0 调用照相机照相报错 FileUriExposedException 解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zuiaisha1/article/details/54986523

Android 7.0 调用照相机照相报错 FileUriExposedException 解决

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mImageCaptureUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//如果是7.0android系统
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(MediaStore.Images.Media.DATA, new File(photoPath, imageFileName).getAbsolutePath());
    mImageCaptureUri= getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
}else{
    mImageCaptureUri = Uri.fromFile(new File(photoPath, imageFileName));
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(intent, REQUEST_PICK_FROM_CAMERA);


猜你喜欢

转载自blog.csdn.net/zuiaisha1/article/details/54986523