EACCES (permission denied)解决办法 android 文件读写

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
已添加,但是依然报如下错误。

EACCES (permission denied)解决办法

在新的os中需要Runtime Permission:

int REQUEST_EXTERNAL_STORAGE=1;
String[] PERMISSIONS_STORAGE={
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};

if (PackageManager.PERMISSION_GRANTED!=
        ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_CONTACTS))
{
    ActivityCompat.requestPermissions(this,PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
}
重载

@Override
public void onRequestPermissionsResult(int requestCode,
                                      String[] permission,
                                      int[] grantResults)

你可能感兴趣的:(android)