I am getting
open failed:
EACCES (Permission denied)
on the line OutputStream myOutput = new FileOutputStream
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.