Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 801
Julio Gorgé Avatar asked Dec 04 '25 21:12

Julio Gorgé


1 Answers

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;
like image 68
Julio Gorgé Avatar answered Dec 06 '25 13:12

Julio Gorgé



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!