java.io.FileNotFoundException: (Permission denied) when writing an object using ObjectOutputStream

后端 未结 3 1735
予麋鹿
予麋鹿 2021-01-20 02:42

I have been trying to work around this for several hours and I am extremely frustrated so I am coming to you guys for some guidance.

I am trying to save and retriev

3条回答
  •  旧时难觅i
    2021-01-20 03:18

    You've added the permission in manifest, So I'm sure you are not asking runtime permissions. If you are using SDK 23 or higher, Ask runtime permission. For reference I'm adding some snippet here:

    if(Build.VERSION.SDK_INT>22){
         requestPermissions(new String[] {YOUR_PERMISSIONS AS STRING}, 1);
    }
    

    and to check whether permission is granted or not, you need to use onRequestPermissionResults() method.

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case 1: {
                if (!(grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
                    Toast.makeText(addAlarm.this, "Permission denied to access your location.", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }
    

提交回复
热议问题