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

六眼飞鱼酱① 提交于 2019-12-02 06:59:40

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();
            }
        }
    }
}

This java.io.FileNotFoundException: /storage/emulated/0myFile.ser looks like you are missing a '/' in the path.

Use

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + '/';

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running

Everything you need to know is in :

https://developer.android.com/training/permissions/requesting.html

The other error has nothing to do with it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!