解决 Android N 7.0 上 报错:android.os.FileUriExposedException
来源:互联网 发布:数据比对公式vlookup 编辑:程序博客网 时间:2024/05/10 07:35
解决 Android N 上 安装Apk时报错:android.os.FileUriExposedException: file:///storage/emulated/0/Download/appName-2.3.0.apk exposed beyond app through Intent.getData()
解决方法
1、在AndroidManifest.xml中添加如下代码
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
注意:
authorities:app的包名.fileProvider
grantUriPermissions:必须是true,表示授予 URI 临时访问权限
exported:必须是false
resource:中的@xml/file_paths是我们接下来要添加的文件
2、在res目录下新建一个xml文件夹,并且新建一个file_paths的xml文件(如下图)
3、打开file_paths.xml文件添加如下内容
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
path:需要临时授权访问的路径(.代表所有路径)
name:就是你给这个访问路径起个名字
4、修改代码适配Android N
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
1、首先我们对Android N及以上做判断;
2、然后添加flags,表明我们要被授予什么样的临时权限
3、以前我们直接Uri.fromFile(apkFile)
构建出一个Uri,现在我们使用FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", apkFile);
4、BuildConfig.APPLICATION_ID
直接是应用的包名
博主最后还有一种方式解决上述问题,建议使用此方式,简单省事,问题少;
在application.oncreate()方法里面调用此代码!!!!!一定要用!!!!!StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();StrictMode.setVmPolicy(builder.build());
阅读全文
0 0
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- android-解决 Android N 上 报错:android.os.FileUriExposedException
- android-解决 Android N 上 报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- 解决 Android N 上 报错:android.os.FileUriExposedException
- Android N共享文件报错:android.os.FileUriExposedException
- (转)Android N安装apk报错:android.os.FileUriExposedException
- 解决android7.0报错:android.os.FileUriExposedException
- Android 7.0 报android.os.FileUriExposedException异常
- 解决android 7.0系统,调用相机报:android.os.FileUriExposedException错
- Android 7.0解析包时出现问题android.os.FileUriExposedException报错解决
- Android 7.0 安装应用报错:android.os.FileUriExposedException
- 解决 Android N 上 安装Apk时报错:android.os.FileUriExposedException: file:///storage/emulated/0/Download/appN
- 安卓7.0报错android.os.FileUriExposedException
- BTrace入门
- C++标准库类型vector
- Linux/UNIX 10个有用的Sar命令监控系统性能的例子
- Haskell学习笔记 --- 基础语法篇一
- 曾优雅击退史上最凶狠的DDoS攻击_AliGuard的高性能从何而来?
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- c++中reverse和resize的区别
- 采用Java阻塞IO对已经到达的socket流实现非阻塞完整读取(一个简单的java http server实现)
- mongodb配置及其开机自启动设置
- **kwargs 的用法
- node mocha 单元测试debug
- MyBatis知识点学习
- poj 1236 Network of Schools 1 (tarjan 缩点)
- 关于php中string类型下的第0个元素