简体   繁体   English

文件权限被拒绝

[英]File permission denied

I'm testing my app on a galaxy S5 with API 22, and a Nexus 6P with API 25. My app is compiled with 23. 我在使用API​​ 22的Galaxy S5和使用API​​ 25的Nexus 6P上测试我的应用程序。我的应用程序编译为23。

I'm trying to read images from an obb file as: 我正在尝试从obb文件中读取图像:

Bitmap bmImg = BitmapFactory.decodeFile(obbPath+"img1.jpg"));

When I run on my Nexus 6P there is no issue, however with the galaxy S5 it gives the error: 当我在Nexus 6P上运行时没有问题,但是对于Galaxy S5,它会给出错误:

01-18 14:42:36.007 14032-14032/com.nick.app E/BitmapFactory: 
Unable to decode stream: java.io.FileNotFoundException: 
/mnt/obb/8a0cd43307e4b1f6568009da3580d11f/img1.jpg: open failed: EACCES (Permission denied)

In my android manifest I have declared the permissions as below: 在我的android清单中,我已经声明了如下权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

This error confuses me that it is on the older device and not the newer with the new runtime permissions which I have not implemented. 这个错误让我感到困惑的是它在旧设备上,而不是新的运行时权限,我还没有实现。 Any suggestions? 有什么建议么?

My app is compiled with 23. 我的应用程序编译为23。

It does not matter what is your compileSdk , however it matters what is set as your targetSdk . 你的compileSdk是什么并不重要,但重要的是你设置的targetSdk If this is 23 or higher, then your manifest permissions does not matter if you run your app on Android 6.0 or newer as in this case you must support runtime permissions as documented here . 如果这是23或更高,那么如果您在Android 6.0或更高版本上运行应用程序,则清单权限无关紧要,因为在这种情况下,您必须支持此处记录的运行时权限。

There are some libs that can simplify the task of implementing runtime permissions, but if you really do not need any of API23+ features in your app you should be able to simply lower targetSdk to ie 22 and then have your manifest permissions honored on any platform. 有一些库可以简化实现运行时权限的任务,但是如果你真的不需要应用程序中的任何API23 +功能,你应该能够简单地将targetSdk降低到22 ,然后在任何平台上获得你的清单权限。

Oddly enough rebooting the device was enough to solve the issue for me. 奇怪的是,重新启动设备足以解决我的问题。 Didn't think to do that at first but it has worked now. 一开始没想到这样做但现在已经奏效了。 This issue seems odd to me but is now fixed. 这个问题对我来说很奇怪,但现在已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM