相关疑难解决方法(0)

android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()暴露在app之外

当我尝试打开文件时,应用程序崩溃了.它可以在Android Nougat下运行,但在Android Nougat上它会崩溃.当我尝试从SD卡打开文件而不是从系统分区打开文件时,它只会崩溃.一些许可问题?

示例代码:

File file = new File("/storage/emulated/0/test.txt");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); // Crashes on this line
Run Code Online (Sandbox Code Playgroud)

日志:

android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()暴露在app之外

编辑:

在定位Android Nougat时,file://不再允许使用URI.我们应该使用content://URI代替.但是,我的应用程序需要打开根目录中的文件.有任何想法吗?

android android-file android-7.0-nougat

682
推荐指数
15
解决办法
38万
查看次数

使用来自上下文提供商的数据或请求Google照片读取权限?

我的应用允许用户从其他应用导入他们的照片和视频.现在谷歌用Google照片取代了Google+照片,但有些事情让我感到震惊.其中一件事是在应用重启后重新使用导入的文件.我感觉他们已经收紧了Google照片使用图片URI返回意图时发出的权限,因此在我的应用程序被杀后,它不再拥有访问上传文件的权限.我正在接受安检:

java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.MediaContentProvider from ProcessRecord{2c17ab9e 2124:com.myapp.myapp/u0a436} (pid=2124, uid=10436) that is not exported from uid 10427
Run Code Online (Sandbox Code Playgroud)

编辑:

我也在重复使用提供的文件时遇到同样的问题 com.google.android.apps.docs.sync.filemanager.FileProvider

有什么建议/解决方法吗?我知道我可以在失去许可之前阅读该文件,所以理论上我可以复制它,但我不能说我非常喜欢这个...

android android-contentprovider google-photos

21
推荐指数
2
解决办法
1万
查看次数