Environment deprecation information
A week and a half ago, in random thoughts about Android 12L, I wrote:
getExternalStorageDirectory()
andgetExternalStoragePublicDirectory()
In ~Environment
Now deprecated.DATA
In ~MediaStore.MediaColumns
Also deprecated.
I don’t know how to do this.
A Google engineer has reached out to clarify the current situation.
good news! These changes are no coincidence!
getExternalStorageDirectory()
and getExternalStoragePublicDirectory()
In ~ Environment
It is safe to use with all supported API levels. 🎉
The fact that they are deprecated means you can rely on them to return the same kind of directory you always have. However,
This will not change your access rights. Scoped storage is still an issue, and what can be read and written is still governed by scoped storage rules.
(Someday I’ll sit down and try to write solid guidelines on what those rules are)
Because for example you can now access DIRECTORY_DOWNLOADS
through
getExternalStoragePublicDirectory()
It doesn’t change the rules for that directory.
-
you can write content there
-
You can read back what you wrote there
-
Content created by other apps, including previous installs of their own apps, cannot be read or written (after the user uninstalls and reinstalls the app).
Therefore, this deprecation has no security impact. This means you won’t get compiler lint complaints about using the deprecated API as soon as you start using it. compileSdkVersion 32
, perhaps in 2022.
Thank you for this change. Deprecation was annoying after Android 11 restored read access to a lot of external storage. This will help simplify the discussion of how to work with external storage in newer Android versions. Because this is a major headache for new Android app developers.
To the Google engineers who made these changes: Thanks!
— November 6, 2021