Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created June 10, 2012 14:48
Show Gist options
  • Save tshirtman/2906019 to your computer and use it in GitHub Desktop.
Save tshirtman/2906019 to your computer and use it in GitHub Desktop.
void android_set_env(char *key, char *value) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/SDLSurfaceView");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "nativeSetEnv", "(Ljava/lang/String;Ljava/lang/String)V");
aassert(mid);
}
(*env)->CallStaticVoidMethod(
env, cls, mid,
(*env)->NewStringUTF(env, key),
(*env)->NewStringUTF(env, value)
);
}
char* android_get_env(char *key) {
static JNIEnv *env = NULL;
static jclass *cls = NULL;
static jmethodID mid = NULL;
jobject jreading;
if (env == NULL) {
env = SDL_ANDROID_GetJNIEnv();
aassert(env);
cls = (*env)->FindClass(env, "org/renpy/android/SDLSurfaceView");
aassert(cls);
mid = (*env)->GetStaticMethodID(env, cls, "nativeGetEnv", "(Ljava/lang/String;)V");
aassert(mid);
}
jreading = (*env)->CallStaticObjectMethod(env, cls, mid);
const char * reading = (*env)->GetStringUTFChars(env, jreading, 0);
POP_FRAME;
return reading;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment