问题
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