Exception 'open failed: EACCES (Permission denied)' on Android

前端 未结 30 1562
[愿得一人]
[愿得一人] 2020-11-22 00:59

I am getting

open failed: EACCES (Permission denied)

on the line OutputStream myOutput = new FileOutputStream

30条回答
  •  不思量自难忘°
    2020-11-22 01:36

    For anyone coming here from search results and are targeting Android 10: Android 10 (API 29) changes some permissions related to storage.

    I fixed the issue when I replaced my previous instances of Environment.getExternalStorageDirectory() (which is deprecated with API 29) with context.getExternalFilesDir(null).

    Note that context.getExternalFilesDir(type) can return null if the storage location isn't available, so be sure to check that whenever you're checking if you have external permissions.

    Read more here.

提交回复
热议问题