Android 7.0 FileUriExposedException 解决(调用系统相机)

来源:互联网 发布:jre 源码 编辑:程序博客网 时间:2024/06/04 22:24

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


阅读全文
0 0