'Android | Creating Folder in External Storage Root Directory on Android 11+

As is well known, Google turned the authorization concept upside down from Android 11 and completely changed it.

I looked in the Android documentation jungle, but didn't find an answer to the question of whether it's still possible to create a folder in the root directory of External Storage (named /storage/emulated/0/). If yes, how?

My app writes at android <= 10 in root.

interim solution could be like this:

 public static String getStorageDir(){

        if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + "/myNewFolder";
            ....

        } else {

        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myNewFolder";
        ...
    }

But that is suboptimal. If a user switches from Android 10 to Android 11+, then there is a big problem. What additional code do I need to allow creating a folder in ROOT on Android 11+?

It is claimed that Google Play denies "MANAGE_ALL_FILES" permission directly. Is that true and is it still the case? Does anyone have experience with this?



Solution 1:[1]

Use ACTION_OPEN_DOCUMENT_TREE to let the user create the wanted directory.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 blackapps