Android7.0中调用系统打开图片报FileUriExposedException

来源:互联网 发布:中国核心期刊数据库 编辑:程序博客网 时间:2024/05/16 09:10
调用系统打开图片
Intent intent = new Intent();File file = new File(fileName);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setAction(Intent.ACTION_VIEW);String type = ImageUtils.getMIMEType(file);//设置intent的data和Type属性。intent.setDataAndType(Uri.fromFile(file), type);
报异常:FileUriExposedException 
解决办法:
在自定义的Application的onCreate方法中添加如下代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();    StrictMode.setVmPolicy(builder.build());}
详情参考:http://blog.csdn.net/xiaoyu940601/article/details/54406725

阅读全文
0 0
原创粉丝点击