This question already has answers here:
java.io.FileNotFoundException: (Permission denied) when writing an object using ObjectOutputStream
                                
                                    (3个答案)
                                
                        
                                去年关闭。
            
                    
Android无法使用FileNotFoundException(PermissionPermission)打开文件,但已授予PermissionRead。


  java.io.FileNotFoundException:/ mnt / obb /“文件详细路径”:打开
  失败:EACCES(权限被拒绝)
  
  obb文件为ERROR_ALREADY_MOUNTED。


int readPermission = ContextCompat.checkSelfPermission(activity, mPermissions[0]);
int writePermission = ContextCompat.checkSelfPermission(activity, mPermissions[1]);

readPermission == 0;
writePermission == 0;


PermissionRead被授予。

Manifest.xml

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


Android OS 6.0版设备。

为什么...?

最佳答案

尝试授予运行时权限

int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);

if (permission != PackageManager.PERMISSION_GRANTED) {
    // We don't have permission so prompt the user
    ActivityCompat.requestPermissions(
            activity,
            PERMISSIONS_STORAGE,
            REQUEST_EXTERNAL_STORAGE
    );
}

关于android - Android无法打开文件FileNotFoundException(权限被拒绝),但是PermissionRead被授予,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53589048/

10-10 20:02