拍照 android.os.FileUriExposedException: file:///storage/emulated/0/ exposed beyond app throu

拍照代码如下

Uri imageUri = null;
String fileName = null;
Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
REQUEST_CODE = TAKE_PICTURE;
fileName = "image.jpg";
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), fileName)); 
//指定照片保存路径(SD卡),image.jpg为一个临时文件,每次拍照后这个图片都会被替换
openCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
 startActivityForResult(openCameraIntent, REQUEST_CODE);

报错:

android.os.FileUriExposedException: file:///storage/emulated/0/image.jpg exposed beyond app through ClipData.Item.getUri()

解决方式 , 现在做的是忽略这个错误 , 暂时file 路径在 7.0中限制的 , 在 application 的 oncreate 方法中添加 

StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值