Do I need to check runtime to write to getExternalFilesDir () on the marshmallow?

In my Android application, I save several files in the Environment.getExternalStorageDirectory() + "\MyApp" directory. This worked great before updating Android 6 Marshmallow. After updating marshmallow, I cannot write to this directory.

As described in this answer, in marshmallows, applications need to ask the user for permission at runtime before writing to external storage.

But, when I use context.getExternalFilesDir(null) instead of Environment.getExternalStorageDirectory() , I don't need to request any permissions at runtime, and it just works (the path returned from context.getExternalFilesDir(null) is also in the external repository directory).

Is this some kind of coincidence, or can I continue to write to context.getExternalFilesDir(null) without asking permission at runtime?

+7
source share
3 answers

The documentation states:

Starting with KITKAT, no permissions are required for reading or writing the returned path; It is always available to the calling application. This applies only to paths generated for the package name of the calling expression. To access paths belonging to other packages, WRITE_EXTERNAL_STORAGE and / or READ_EXTERNAL_STORAGE.

You will have read and write access to getExternalFilesDir() on Android 4.4+ without any permissions.

I would recommend using FileProvider if you need to support lower API levels.

+9
source

As I know, PERMISSIONS are introduced starting with Android 6 and higher. Therefore, there is no need to check permissions for API 16

0
source
 <uses-permission android:maxSdkVersion="18" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

reference: uses-permission-element

0
source

All Articles