In my android app, I save some files to Environment.getExternalStorageDirectory() + "\MyApp"
directory. This worked fine until android 6 marshmallow update. After marshmallow update, I cannot write to this directory.
As described in this answer, in marshmallow, apps need to ask for the permission from user at runtime before writing to external storage.
But, when I use context.getExternalFilesDir(null)
instead of Environment.getExternalStorageDirectory()
, I don't need to ask for any permission at runtime and it just works (path returned from context.getExternalFilesDir(null)
is also inside the external storage directory).
Is this some kind of a coincidence or can I continue to write to context.getExternalFilesDir(null)
without asking permission at runtime?