安卓7.0拍照,FileUriExposedException: file:/// ****** exposed beyond app through ClipData.Item.getUri()
来源:互联网 发布:书店管理系统c语言 编辑:程序博客网 时间:2024/06/08 10:30
前段时间把App的有关拍照的代码写好了,也适配了安卓7.0,但当时公司没有安卓7.0的手机进行测试,所以一直没有测过,这不,把我们老大的三星的手机搞来玩玩,偷偷给升级到了安卓7.0来测一下,果然出了问题,很时棘手,
FileUriExposedException: file:////XXXXXXXX g exposed beyond app through ClipData.Item.getUri()
这是什么错误,特别是后面的exposed beyond app through ClipData.Item.getUri(),我都没看懂,所以到网上找这是个解决方案
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);if (cameraIntent.resolveActivity(getPackageManager()) != null) { mTmpFile = new File(FileUtils.createRootPath(getBaseContext()) + "/" + System.currentTimeMillis() + ".jpg"); FileUtils.createFile(mTmpFile); if(Build.VERSION.SDK_INT < 24){ cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT ,Uri.fromFile(mTmpFile)); startActivityForResult(cameraIntent, REQUEST_CAMERA); }else { //适配安卓7.0 ContentValues contentValues=new ContentValues(1); contentValues.put(MediaStore.Images.Media.DATA, mTmpFile.getAbsolutePath()); Uri uri= getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues); grantUriPermission("你的App包名",uri,Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,uri); startActivityForResult(cameraIntent, REQUEST_CAMERA); }}
这一回应该可以了,没错,真的行了,我已开始是写的FileProvider模式的,然后再用Intent传递uri,一直报错,不知道咋地。像这样的
File cameraPhoto = new File(cameraPhotoPath); Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri photoUri = FileProvider.getUriForFile( this, getPackageName() + ".provider", cameraPhoto); takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(takePhotoIntent, REQUEST_TAKE_PHOTO);
一直出错,不知道咋地,感觉不爱了!!!
后来在CSDN上找到一个帖子
有需要的小伙伴可以去看看,所以我在此基础上出篇博客,收录一下。
好了,mark这里,谁有需要直接拷代码就行了,还有记得在调起相机前申请存储权限,和调用相机权限(Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.CAMERA)。
阅读全文
1 0
- 安卓7.0拍照,FileUriExposedException: file:/// ****** exposed beyond app through ClipData.Item.getUri()
- android 7.0拍照问题file:///storage/emulated/0/photo.jpeg exposed beyond app through ClipData.Item.getUri
- Android 7.0 系统解决拍照的问题 exposed beyond app through ClipData.Item.getUri()
- 解决exposed beyond app through ClipData.Item.getUri() 错误
- Android系统7.0以上遇到exposed beyond app through ClipData.Item.getUri
- android.os.FileUriExposedException: file:///sdcard/update/wiiwork.apk exposed beyond app through I
- android.os.FileUriExposedException:file:///storage/emulated/0/1502852028434.jpg exposed beyond app t
- 下载APK后打开APK,在安装时的报错 android.os.FileUriExposedException:exposed beyond app through Intent.getData()
- Android 调用相机拍照时报错FileUriExposedException .jpg beyond app through Intent.getData()
- Android7.0须知--应用间共享文件(FileProvider) log: exposed beyond app through Intent.getData()
- Android 7.0 拍照 FileUriExposedException
- android 7.0 + 相机拍照 FileUriExposedException
- android 7.0 + 相机拍照 FileUriExposedException
- 安卓7.0报错android.os.FileUriExposedException
- Android7.0android.os.FileUriExposedException: file:///storage/emulated/0/through Intent.getData()
- Android 7.0 拍照并显示照片出现"FileUriExposedException"
- Android 7.0拍照出现android.os.FileUriExposedException异常
- android 7.0系统解决拍照的问题android.os.FileUriExposedException:
- idea 中使用dataBase插件
- 外边缘描边发光Shader
- Oracle 5个后台进程详解
- 堆转储文件分析
- OpenCV常用类之Rect矩形类
- 安卓7.0拍照,FileUriExposedException: file:/// ****** exposed beyond app through ClipData.Item.getUri()
- 如何选择适合的前端UI框架
- 4.3.2 BroadcastReceiver庖丁解牛--LocalBroadcastManager
- 你会对React说再见吗?Facebook开源协议让你开开眼
- 23种设计模式(1):单例模式
- web图标
- c/c++内存分配机制
- 从零开始···将工程上传到github
- 代码审计方法与准备