5

In my application I use native function fdopendir. From java I get file descriptor which I put inside this function. Using it's result I can read content of the directory. On android 11 while listing the directory I see only media files. How to get full file list using Storage Access Framework?

here is my code :

In native code I iterate through directory entries using readdir. dirp is my own structure which contains pointer to standard DIR structure.

struct dirent* dentry = readdir(dirp->dir);

To get DIR structure I jump to Java for file descriptor

DIR *AndroidStorage_OpenDir(const char *folder) {
    jstring string = jvmEnv->NewStringUTF(folder);
    int fd = jvmEnv->CallIntMethod( jvmCallbackThread, JavaOpenDir, string);
    jvmEnv->DeleteLocalRef(string);
    return fdopendir(fd);
}

In Java I use SAF method for getting integer file descriptor, then I return it back to c++

public static int openDir(String path) {
        Uri uri = uriCache.get(path);
        if (uri == null) {
            uri=getUri(path);
            uriCache.put(path, uri);
        }
    return resolver.openFileDescriptor(uri, "r").detachFd();
}

On Android 10 and lower it works fine. What should I do on android 11 to get all files inside directory? User granted me full access on this folder using Intent.ACTION_OPEN_DOCUMENT_TREE

EDIT: I opened issue on google's tracker, because it seems to me a bug. You can find there small application for reproducing. You can star the issue, so google can look at this this faster.

user1063364
  • 791
  • 6
  • 21

0 Answers0