手机安装迅雷软件引起的获取本地图片问题
常规写法通过Intent.ACTION_PICK打开系统相册,手机上安装了迅雷软件后上传图片选择从手机相册选取会弹出如下选择框:如果选择最左侧,本地图片则返回的Uri会是content://com.xunlei.fileexplorer.FileExplorerFileProvider/external_storage_root/attendance.jpg 这种样子的,然而我们get不到图..
常规写法通过Intent.ACTION_PICK打开系统相册,手机上安装了迅雷软件后上传图片选择从手机相册选取会弹出如下选择框:
如果选择最左侧,本地图片则返回的Uri会是content://com.xunlei.fileexplorer.FileExplorerFileProvider/external_storage_root/attendance.jpg 这种样子的,然而我们get不到图片,报错信息如下:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { act=android.intent.action.VIEW dat=content://com.xunlei.fileexplorer.FileExplorerFileProvider/external_storage_root/UCDownloads/pictures/B3534KHB29A30008.jpg }} to activity {com.xx/com.xx.XxActivity}: java.lang.SecurityException: Permission Denial: opening provider com.xunlei.fileexplorer.FileExplorerFileProvider from ProcessRecord{e92a5c9 16462:com.rch/u0a287} (pid=16462, uid=10287) that is not exported from uid 10150
第一次遇到这个由于第三方软件引起的本地图片选取问题,暂时采用了更换图片路径的方法规避这个问题。
解决方案:
首先通过data.getData().getEncodedPath()获取图片的真实路径,但实际上这个路径在使用的时候还是会报FileNotFoundException,所以判断手机sd卡是否存在,如果存在则修改一下路径,由于我们项目中是通过uri对图片进行处理的,为了减少代码变动又手动将图片路径转为uri进行后续操作了,贴一下代码:
更多推荐
所有评论(0)