Android 7.0拍照出现android.os.FileUriExposedException异常
来源:互联网 发布:smali语法编程 编辑:程序博客网 时间:2024/06/07 04:42
最近上线的一个app在客户那里反馈调用手机系统拍照时崩溃的问题,说使用的是Android 7.0系统,后来费劲找来一个Android 7.0的手机调试了一下,发现不能再用以前的方式来调用:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pictureFile)); mCurrentFragment.startActivityForResult(intent, REQUEST_CODE_FORM_CAMERA);
这时会抛出异常:
FATAL EXCEPTION: main
Process: com.test.android.debug, PID: 19189
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/com.test.android.debug/files/Pictures/bs20170419092740.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1816)
at android.net.Uri.checkFileUriExposed(Uri.java:2350)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
这个异常只会在Android 7.0以及以上版本才会出现,是说通过此方式会出现暴露文件Uri的异常,这个Uri可以通过ClipData.Item.getUri() 方法获取到。后来查了一下需要使用以下方式:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { doTakePhotoIn7(pictureFile.getAbsolutePath()); } else { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pictureFile)); mCurrentFragment.startActivityForResult(intent, REQUEST_CODE_FORM_CAMERA); }//在Android7.0以上拍照 private void doTakePhotoIn7(String path) { Uri mCameraTempUri; try { ContentValues values = new ContentValues(1); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg"); values.put(MediaStore.Images.Media.DATA, path); mCameraTempUri = mCurrentFragment.getActivity().getContentResolver() .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); takePhoto(mCurrentFragment, REQUEST_CODE_FORM_CAMERA, mCameraTempUri); } catch (Exception e) { e.printStackTrace(); } } public static void takePhoto(Fragment fragment, int requestCode, Uri uri) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (uri != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); } fragment.startActivityForResult(intent, requestCode); }
1 0
- Android 7.0拍照出现android.os.FileUriExposedException异常
- Android 7.0 报android.os.FileUriExposedException异常
- Android 7.0 拍照 FileUriExposedException
- android 7.0系统解决拍照的问题android.os.FileUriExposedException:
- android 7.0 + 相机拍照 FileUriExposedException
- android 7.0 + 相机拍照 FileUriExposedException
- Android 7.0 拍照并显示照片出现"FileUriExposedException"
- Android 7.0 android.os.FileUriExposedException
- android.os.FileUriExposedException 解决方法
- android.os.FileUriExposedException
- android.os.FileUriExposedException
- android 7.0的android.os.FileUriExposedException: 问题解决
- Android 7.0之后安装APK,拍照 出现FileUriExposedException,多个provider配置
- Android N FileUriExposedException异常
- Android 7.0解析包时出现问题android.os.FileUriExposedException报错解决
- Android7.0 android.os.FileUriExposedException
- Android 7.0调用相机拍照 报错 FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 并发
- Win7 64位下安装apache httpd-2.4.18 + php 7.0.1
- springboot输出日志到指定目录,简单粗暴,springboot输出mybatis日志
- Problem A: 还会用继承吗?
- 针对机器学习初学者的MNIST实验——回归的实现、训练和模型评估
- Android 7.0拍照出现android.os.FileUriExposedException异常
- (字典树Trie Tree)HDU 1251 统计难题
- Problem B: 一切皆对象
- Android中ListView适配器中的view重用和接口回调
- 数据库
- 区间覆盖问题
- HTML5 canvas 中的 fillstyle fillrect strokeStyle strokeRect fill stroke rect 的简单理解
- chapter6指针——输入三个整数,按从小到大顺序输出
- Problem C: 给我一台计算机吧!