Reputation: 5597
As mentioned in the documentation, the WRITE_EXTERNAL_STORAGE permission should not be a requirement starting from API level 19. Hence, I've written this to the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>
However, when running my app which uses Google Maps V2 and thus needs access to the external storage, I get a SecurityException
:
java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
The phone I'm running the app is KitKat (4.4) which is API level 19. To my understanding, the app should be able to run fine without the permission. Why do I get the error anyway?
Upvotes: 5
Views: 2451
Reputation: 67189
According to the WRITE_EXTERNAL_STORAGE
documentation (emphasis mine):
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().
The Google Maps API is presumably using directories on the external storage that are not specific to your application, and thus you need to include the permission for all API levels.
Upvotes: 1
Reputation: 1006759
the WRITE_EXTERNAL_STORAGE permission should not be a requirement starting from API level 19
Only if you are using methods on Context
, like getExternalFilesDir()
, to get at standard locations on external storage that are specific for your app. For other locations, such as the paths reported by methods on Environment
, you still need the permission.
Or, to quote the documentation that you linked to:
For example, beginning with Android 4.4 (API level 19), it's no longer necessary for your app to request the WRITE_EXTERNAL_STORAGE permission when your app wants to write to its own application-specific directories on external storage (the directories provided by getExternalFilesDir()).
Also, third-party libraries are welcome to require that you have this permission for their own reasons.
Why do I get the error anyway?
It looks like MapsV2 is validating that you have the permission as part of its setup process. That is the prerogative of MapsV2. Perhaps they are looking to work with external storage outside of the limited areas that do not require this permission. Perhaps they aren't but failed to update the permission check in their code. MapsV2, being closed source, is difficult to analyze for this sort of thing.
Upvotes: 2