FileNotFoundException: open failed: EACCES (Permission denied)

后端 未结 2 837
梦毁少年i
梦毁少年i 2021-01-18 20:16

In emulator (i use genymotion) it works fine, but when I run it on a real device (my phone is ASUS ZenFone Laser 5.0) throws a filenotfoundexception

java.io.

相关标签:
2条回答
  • 2021-01-18 20:28

    I suspect WRITE_EXTERNAL_STORAGE overrides the READ_EXTERNAL_STORAGE read permission. If you look into the documentation you'll see that the former also permits reading from storage.

    Try and remove the android:maxSdkVersion attribute and see if that works. I suspect that your device runs an SDK version > 18.

    Check out this answer for more info: https://stackoverflow.com/a/15270626/425238

    0 讨论(0)
  • 2021-01-18 20:43

    you have to request permission before you start your instructions because this permission is considered dangerous in Marshmallow:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 
    checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) 
         {
          requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, RESULT);
         } 
        else
         {
        //your code
         }
    
    0 讨论(0)
提交回复
热议问题