As was first disclosed back in March 2019, you no longer have access by default to arbitrary locations on external storage or removable storage on Android 10+. This includes Environment.getExternalStorageDirectory()
and other methods on Environment
(e.g., getExternalStoragePublicDirectory()
.
For Android 10 and 11, you can add android:requestLegacyExternalStorage="true"
to your <application>
element in the manifest. This opts you into the legacy storage model, and your existing external storage code will work.
Otherwise, your choices are:
-
Use methods on
Context
, such asgetExternalFilesDir()
, to get at directories on external storage into which your app can write. You do not need any permissions to use those directories on Android 4.4+. However, the data that you store there gets removed when your app is uninstalled. -
Use the Storage Access Framework, such as
ACTION_OPEN_DOCUMENT
andACTION_CREATE_DOCUMENT
. -
If your content is media, you can use
MediaStore
to place the media in standard media locations.