Android7.0须知--应用间共享文件(FileProvider) log: exposed beyond app through Intent.getData()
来源:互联网 发布:网络购物用户行为报告 编辑:程序博客网 时间:2024/06/14 04:39
- 对于面向 Android N 的应用,Android 框架执行的 StrictMode,API 禁止向您的应用外公开 file://URI。
如果一项包含文件 URI 的 Intent 离开您的应用,应用失败,并出现 FileUriExposedException异常。
若要在应用间共享文件,您应发送一项 content://URI,并授予 URI 临时访问权限。
进行此授权的最简单方式是使用 FileProvider类。 如需有关权限和共享文件的更多信息,
解决
AndroidManifest.xml中添加一个provider
<provider android:name="android.support.v4.content.FileProvider" android:authorities="APP包名.fileprovider" android:grantUriPermissions="true" android:exported="false" > <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /><?/provider>
添加一个XML文件 名为 file_paths.xml
<xml version="1.0" encoding="utf-8"?><paths> <external-path path="你需要访问的路径" name="files_root" /> <external-path path="." name="external_storage_root" /></paths>
然后调用安装的时候 判断下sdk版本 做区分对待
Intent intent = Intent intent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(context, "com.coderstory.Purify.fileprovider", new File(filePath)); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } startActivity(intent);
new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(context, "com.coderstory.Purify.fileprovider", new File(filePath)); intent.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } startActivity(intent);
阅读全文
0 0
- Android7.0须知--应用间共享文件(FileProvider) log: exposed beyond app through Intent.getData()
- Android7.0须知--应用间共享文件(FileProvider)
- Android7.0须知--应用间共享文件(FileProvider)
- Android7.0须知--应用间共享文件(FileProvider)
- Android7.0 应用间共享文件 FileProvider
- 下载APK后打开APK,在安装时的报错 android.os.FileUriExposedException:exposed beyond app through Intent.getData()
- Android 调用相机拍照时报错FileUriExposedException .jpg beyond app through Intent.getData()
- Android7.0 使用FileProvider 共享文件
- Android7.0android.os.FileUriExposedException: file:///storage/emulated/0/through Intent.getData()
- Android 应用间共享文件(FileProvider)
- 解决exposed beyond app through ClipData.Item.getUri() 错误
- android7.0 应用间共享文件
- Android N 7.0 应用间共享文件(FileProvider)
- android 7.0应用间共享文件----FileProvider
- android 7.0拍照问题file:///storage/emulated/0/photo.jpeg exposed beyond app through ClipData.Item.getUri
- android.os.FileUriExposedException: file:///sdcard/update/wiiwork.apk exposed beyond app through I
- Android 7.0 系统解决拍照的问题 exposed beyond app through ClipData.Item.getUri()
- 安卓7.0拍照,FileUriExposedException: file:/// ****** exposed beyond app through ClipData.Item.getUri()
- 一个新手对java网站项目管理的理解,浅谈MVN,Git,SVN
- CodeForces
- 1248: Let the Balloon Rise
- iOS-浅谈runtime运行时机制01-类与对象的内部结构
- 华为面试---取近似值
- Android7.0须知--应用间共享文件(FileProvider) log: exposed beyond app through Intent.getData()
- C语言笔记-基于C语言实现的流水跑马灯
- 典型的找不到mapper映射文件的异常 Invalid bound statement 异常
- Android transaction Fragment时按返回键直接退出,没有返回到上一个Fragment
- HDU 3076 ssworld VS DDD (概率dp)
- JAVA多线程
- 我的python进阶之路,开始
- 扫雷 java 实现 uva 题号10189
- Teradata