Search code examples
androidandroid-permissionsandroid-versionandroid-storage

Do I need to explicitly declare WRITE_EXTERNAL_STORAGE permission on Android 4.1 and earlier?


Regarding the WRITE_EXTERNAL_STORAGE, the Android docs state that

Starting in API level 19, this permission is not required to read/write files in your application-specific directories returned by getExternalFilesDir(String) and getExternalCacheDir().

My app only reads and writes to the Android/data//files directory. Does that mean that, in order to read and write to this specific directory whenever my app runs on Android versions earlier than 19, I still will need to declare this permission in the manifest?


Solution

  • Android doc says here:

    Beginning with Android 4.4, reading or writing files in your app's private directories does not require the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permissions. So you can declare the permission should be requested only on the lower versions of Android by adding the maxSdkVersion attribute:

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

    So the answer is explicitly YES.