Android10共享文件总是读取不到文件,文件资源不存在!
16lz
2021-01-23
1、Android共享文件
坑:共享的文件不能在软件数据文件夹,否则就会获取不了
//首先最前面加入此三行,否则会闪退StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();StrictMode.setVmPolicy(builder.build());builder.detectFileUriExposure();//分享文件Intent intent = new Intent();intent.setAction(Intent.ACTION_SEND);//设置intent的data和Type属性。intent.setType("*/*");//设置为所有文件intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); // 必须添加这一句,否则找不到资源getContext().startActivity(intent);
注意:path路径来自sd卡文件,否则会读取不到文件。
文件来源:
解决:
Environment.getExternalStorageDirectory().getPath()
使用sd卡目录获取文件
更多相关文章
- Android学习之文件存储
- Android InputStreamReader 解析gbk、gb2312编码的xml文件 编码
- android实现文件下载的几种方式
- Android Studio 3.0以后打包修改文件名方法
- Android 下载文件至SD卡,并用progressBar显示下载进度
- Android 文件IO总结
- Android--取出SDcard卡上指定后缀名的文件
- AndroidManifest.xml文件详解(service)