I'm working on porting PC OpenGL application onto Android. I've chosen to use that NDK android_native_app_glue framework stuff. As I understood, it would allow to me stay on C++ and write no even single JAVA code line. And it sounded promising.
The first unclear thing to me it data saving/loading. My application's data format is binary and my original PC-related code uses plain "stdio.h" FILE operations: fopen, fread, fwrite, etc to create, write and read from "mygame.bin" file. How do I port it onto Android?
Having googled it, I found that I must store and then use a "java environment" variable:
JNIEnv *g_jniEnv = 0;
void android_main(struct android_app* state) {
g_jniEnv = state->activity->env;
}
However, I still do not realize how to use this g_jniEnv to perform file operations.
Update: Okay, I found that in Java, data saving can be performed as follows:
String string = "hello world!";
FileOutputStream fos = openFileOutput("mygame.bin", Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
So my questions is: given a pointer to JNIEnv, how do I rewrite this code fragment in C++?