FileNotFoundException: open failed: EACCES (Permission denied)

后端 未结 2 855
梦毁少年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: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
         }
    

提交回复
热议问题