My problem is that for an Android project I have to create a folder in the external memory of the phone and this can be done for Android 11enter image description here and lower phones. What permissions and codes should I add to my project?
2 Answers
if you have to support Android 11 then you have to support Scoped Storage for accessing whole storage, not only app-restricted folder (basing on screen of external root folder). check out THIS doc for more
question is which perms are needed, so for full access to whole content you need
// works till Android 9/10
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
// for Android 10/11
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
I strongly suggest: don't use second permission, store your data in app-restricted folder (as stays in linked doc, getExternalFilesDirs()
method), then just WRITE_EXTERNAL_STORAGE
will be sufficient
and how to create folder? HERE you have some examples, just don't use getExternalStorageDirectory()
, instead use getExternalFilesDirs()
for accessing app-restricted folder (or use getExternalStorageDirectory()
, but then you need second permission declared for Android 11)

- 17,866
- 3
- 32
- 74
For an Android 11 device:
Use Storage Access Framework and ACTION_OPEN_DOCUMENT_TREE to let the user create and choose that Pixir directory.
Not a single permission needed.
After that you can create as much files and subdirs in it as you want using saf methods.
If a directory Documents/Pixir could do too than you could use your old classic files code and usual permissions to create files and folders in it.

- 8,011
- 2
- 11
- 25