EACCESS Permission denied in Android

后端 未结 4 933
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 12:28

While writing file in External SD card I am getting an error EACCESS permission denied. I have set the permission

4条回答
  •  不思量自难忘°
    2020-12-06 12:43

    Check if user is having external storage permission or not. If not then use cache dir for saving the file.

    final boolean extStoragePermission = ContextCompat.checkSelfPermission(
                   context, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    == PackageManager.PERMISSION_GRANTED;
    
                if (extStoragePermission &&
            Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) {
                    parentFile = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
                }
                else{
                    parentFile = new File(context.getCacheDir(),    Environment.DIRECTORY_PICTURES);
                }
    

提交回复
热议问题