How do I write to the internal storage file system with NativeActivity?

筅森魡賤 提交于 2019-11-29 22:43:57

问题


I'm porting a pure C++ game over to Android, and since my target is Android 3.0+ tablets, I opted to use NativeActivity in order to avoid Java completely. However, I am not able to see any functionality that lets me write to the device's internal storage. Calls to fopen() will fail as I have no idea which directory I am supposed to write and the internal storage filesystem is not accessible

This code usually does the trick on Java, giving me the path to the internal writable data directory for my app:

mContext.getFilesDir();

Does anybody know an alternative for C++? Otherwise I'll have to call the snippet above with JNI.

Of course, I have looked into the $NDK/..../include/android/ headers but I see no candidate methods for what I need.


回答1:


I finally found it. Turns out the path to the internal storage directory is declared as a member of ANativeActivity in android/native_activity.h:

/**
 * Path to this application's internal data directory.
 */
const char* internalDataPath;


来源:https://stackoverflow.com/questions/6525724/how-do-i-write-to-the-internal-storage-file-system-with-nativeactivity

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