How to access Android Lollipop DocumentFile files via NDK?

♀尐吖头ヾ 提交于 2019-12-04 18:07:38

问题


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 this to access the external SD-Card files via the NDK.


回答1:


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



来源:https://stackoverflow.com/questions/30593964/how-to-access-android-lollipop-documentfile-files-via-ndk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!