Android 7.0的适配问题,android.os.FileUriExposedException
来源:互联网 发布:mac如何装win10虚拟机 编辑:程序博客网 时间:2024/06/16 11:34
编写不易,如有转载,请声明出处: 梦回河口:http://blog.csdn.net/zxc514257857/article/details/70766998
报错问题:
最近在集成AutoInstaller实现应用程序静默更新的时候出现了这样一个报错:
android.os.FileUriExposedException: file:///storage/emulated/0/Download/update-1.0.2.apk exposed beyond app through Intent.getData()
报错原因:
Android 7.0以后提高了私有文件的安全性,其私有目录将会限制访问。若要在应用间共享文件,您需要发送一项 content:// URI,并授予 URI 临时访问权限。
解决方法:
AndroidManifest.xml中application节点下面添加如下代码:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="top.wuhaojie.installerlibrary.fileProvider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /></provider>
注:android:authorities=”你应用程序包名.fileProvider”
在app—>res下新建一个xml文件夹,文件夹中新建file_paths.xml文件,写入代码如下:
<paths> <external-path path="Android/data/top.wuhaojie.installerlibrary/" name="files_root" /> <external-path path="." name="external_storage_root" /></paths>
注: < external-path path=”Android/data/你应用程序包名/” name=”files_root” />
在报错代码的位置做如下修改(AutoInstaller源码第119行installUseAS()方法):
private void installUseAS(String filePath) { File apkFile = new File(filePath); Uri uri = Uri.fromFile(apkFile); Intent intent = new Intent(Intent.ACTION_VIEW); //判断是否是AndroidN以及更高的版本 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", apkFile); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); }else{ intent.setDataAndType(uri, "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } mContext.startActivity(intent); if (!isAccessibilitySettingsOn(mContext)) { toAccessibilityService(); sendEmptyMessage(OPENSERVICE); }}
参考资料:
解决 Android N 7.0 上 报错:android.os.FileUriExposedException http://blog.csdn.net/yy1300326388/article/details/52787853
在此项目中报出如下错误:
Android中自己实现App一打开判断是否有更新,并通过依赖AutoInstaller实现自动更新
http://blog.csdn.net/zxc514257857/article/details/72667640
Demo下载请移步:http://download.csdn.net/detail/zxc514257857/9850244
———-因本人才疏学浅,如博客或Demo中有错误的地方请大家随意指出,与大家一起讨论,共同进步,谢谢!———-
- 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.os.FileUriExposedException 解决方法
- android.os.FileUriExposedException
- android.os.FileUriExposedException
- Android 7.0 报android.os.FileUriExposedException异常
- 【适配整理】Android 7.0 调取系统相机崩溃解决android.os.FileUriExposedException
- Android7.0 android.os.FileUriExposedException
- Android 7.0解析包时出现问题android.os.FileUriExposedException报错解决
- 解决Android7.0以上版本升级apk时报android.os.FileUriExposedException的问题
- 解决 Android N 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 7.0 上 报错:android.os.FileUriExposedException
- 解决 Android N 7.0 上 报错:android.os.FileUriExposedException
- hBuilder天蓝主题插件
- python_获取当前代码行号_获取当前运行的类名和函数名的方法
- JD Quant50篇干货合集,揭开量化交易之谜
- spring的事务中程序控制事务成功失败(Transaction marked as rollback)
- 第26节:Scala的核心力量和黄金定律
- Android 7.0的适配问题,android.os.FileUriExposedException
- C语言程序设计习题
- [ASIFT 3] Computing ASIFT keypoints and matching
- 死锁&活锁&饥饿
- hdu-4632 Palindrome subsequence
- 数字图像处理做过的小程序
- linux分区加密
- 详谈Picasso图片缓存库特点及用法
- 好玩的API调用之---IP地址查询API