如何通过NDK访问Android Lollipop DocumentFile文件? [英] How to access Android Lollipop DocumentFile files via NDK?

查看:130
本文介绍了如何通过NDK访问Android Lollipop DocumentFile文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问从 DocumentFile 生成的文件在本机JNI代码中的Android KitKat/Lollipop中,因此我可以使用fopen,fread等. 我特别要求它通过NDK访问外部SD卡文件.

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.

推荐答案

您可以使用文件描述符:

You can use file descriptors:

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

此int fd可以传递给JNI并用作常规的C ++文件描述符:

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

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

您需要访问SD卡上文件或目录的权限

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

这篇关于如何通过NDK访问Android Lollipop DocumentFile文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆