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

1

3

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.

Pillsbury answered 29/6, 2011 at 18:54 Comment(0)
P
9

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;
Pillsbury answered 29/6, 2011 at 20:2 Comment(2)
Just for reference: apparently there's a known bug where internalDataPath and externalDataPath don't work (are always NULL) on gingerbread.Ohmmeter
Are you using NativeActivity, or good old Java+JNI? Those vars are meant for pure native apps only.Sinful

© 2022 - 2024 — McMap. All rights reserved.