public static Uri getPseudoTreeUriForFileUri(final Uri legacyDirectory) {

        //works only for File Uris!
        if (!(UriUtils.isFileUri(legacyDirectory))) {
            return legacyDirectory;
        }

        // Separate each element of the File path
        // File format: "/storage/XXXX-XXXX/sub-folder1/sub-folder2..../folder"
        //  ele[0] = (empty)
        //  ele[1] = not used (storage name)
        //  ele[2] = storage number ("XXXX-XXXX" for external removable or "primary" for internal)
        //  ele[3 to n] = folders
        final String[] ele = legacyDirectory.getPath().replace("/emulated/0/", "/primary/").split("/");
        if (ele.length < 3) {
            //something seems not right. Log for analysis and continue
            Log.v("[getPseudoTreeUriForFileUri] uri could not be parsed to pseudo tree: " + legacyDirectory);
            return legacyDirectory;
        }

        // Construct folders strings using SAF format
        final StringBuilder folders = new StringBuilder();
        if (ele.length > 3) {
            folders.append(ele[3]);
            for (int i = 4; i < ele.length; ++i) {
                folders.append("%2F").append(ele[i]);
            }
        }
        final String common = ele[2] + "%3A" + folders;

        // Construct TREE Uri
        return new Uri.Builder()
                .scheme(SCHEME_CONTENT)
                .authority("com.android.externalstorage.documents")
                .encodedPath("/tree/" + common + "/document/" + common)
                .build();
    }
Returns a PSEUDO-Tree-Uri based on the given path. This URI can be used e.g. as EXTRA_INITIAL_URI when requesting access to a folder
The returned URI might be OK but also could simply be bullshit, so non't use this function when the URI must always be valid!
<br>
Note that the returned URI CAN'T and SHOULDN'T be used to access the directory.

@param legacyDirectory file uri which points to the directory
main/src/main/java/cgeo/geocaching/utils/UriUtils.java