android.os.FileUriExposedException: file:///storage/emulated/0/myimage/15115
来源:互联网 发布:视频加马赛克软件 编辑:程序博客网 时间:2024/06/07 02:39
当遇到这个问题的时候处理方法有2种
第一
//取消严格模式 FileProviderif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy( builder.build() );}
第二种方法
1 在AndroidManifest.xml中添加如下代码
<provider android:name="android.support.v4.content.FileProvider" android:authorities="包名.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/></provider>
注意: authorities:app的包名.fileProvider grantUriPermissions:必须是true,表示授予 URI 临时访问权限 exported:必须是false resource:中的@xml/file_paths是我们接下来要添加的文件
2、在res目录下新建一个xml文件夹,并且新建一个file_paths的xml文件(如下图)
3、打开file_paths.xml文件添加如下内容
<?xml version="1.0" encoding="utf-8"?><paths> <external-path name="external_files" path="."/></paths>
4 修改代码
Uri imageUri = Uri.fromFile(file);//原来的 Uri imageUri = FileProvider.getUriForFile(MainActivity.this, MainActivity.this.getApplicationContext().getPackageName() + ".provider", file);
如果你的方法里面传入的context那么可以直接用上下文即可
如下
public static void installApkFile(Context context, String filePath) { 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.yuneec.android.saleelfin.fileprovider", new File(filePath)); intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
阅读全文
0 0
- android.os.FileUriExposedException: file:///storage/emulated/0/myimage/15115
- Android7.0解决 android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- (转)解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
- Android7.0android.os.FileUriExposedException: file:///storage/emulated/0/through Intent.getData()
- android.os.FileUriExposedException:file:///storage/emulated/0/1502852028434.jpg exposed beyond app t
- Android 7.0调用系统相机报错Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/rpms/14
- 解决 Android N 上 安装Apk时报错:android.os.FileUriExposedException: file:///storage/emulated/0/Download/appN
- 开发中碰到的问题:Android 7.0 更新APK在安装时的报错 android.os.FileUriExposedException: file:///storage/emulated/0/And
- Android7.0 android.os.FileUriExposedException
- android 7.0拍照问题file:///storage/emulated/0/photo.jpeg exposed beyond app through ClipData.Item.getUri
- 找不到/storage/emulated/0文件
- /storage/emulated/0保存路径
- 基于gensim的Doc2Vec简析,以及用python 实现简要代码
- uva11512
- 别人总结的学习数据结构的经验
- SpirngMVC第一个程序
- 大数据从0到一(HDFS)
- android.os.FileUriExposedException: file:///storage/emulated/0/myimage/15115
- 软件调试笔记12
- C++知识点杂谈
- JVM——Java虚拟机架构
- 用openssl为apache制作ssl证书
- linux 安装配置zookeeper
- 一款相对比较简单 聊天界面的 表情输入库:
- windows下安装AnyProxy抓取移动App Http请求
- 学习笔记——插入排序和希尔排序