How to access Android Lollipop DocumentFile files via NDK?

后端 未结 1 1450
傲寒
傲寒 2021-02-13 14:48

How is it possible to access files which are generated from a DocumentFile in Android KitKat/Lollipop in Native JNI Code, so I can use fopen, fread, etc. I\'m particular asking

1条回答
  •  名媛妹妹
    2021-02-13 15:32

    You can use file descriptors:

    ParcelFileDescriptor filePfd;
    DocumentFile file;
    filePfd = getContentResolver().openFileDescriptor(file.getUri(), "w");
    int fd = filePfd.getFd();
    

    This int fd can be passed to JNI and used as usual C++ file descriptor:

    FILE* file = NULL;
    file = fdopen(fd, "r+b");
    

    And you need permission to access to file or directory on SD-card

    0 讨论(0)
提交回复
热议问题