al_android_get_jni_env(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– al_android_get_jni_env πŸ’–

okay so bestie, you're in the Allegro 5 API docs, section 3alleg5, and this page is all about one lil function that hands you the JNI environment. yes it's as cute as it sounds. let's go 🫢


✨ NAME ✨

al_android_get_jni_env β€” the Allegro 5 API function that gives you the Android JNI env, no cap πŸ‘‘


🌸 SYNOPSIS 🌸

#include <allegro5/allegro_android.h>

JNIEnv *al_android_get_jni_env(void)

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: this returns the Android JNI environment that Allegro itself uses to call into Java. and because Allegro is a generous queen πŸ‘‘, it hands it to you as a lil convenience β€” so there's literally no need for you to go get it yourself. you're welcome, bestie πŸ’…

like, say you've got a Java method void send(String message) chillin' in your activity class. you can call it from C code like this, periodt:

JNIEnv * env = al_android_get_jni_env();
jclass class_id = (* env)->GetObjectClass(env, al_android_get_activity());
jmethodID method_id = (* env)->GetMethodID(env, class_id, "send",
    "(Ljava/lang/String;)V");
jstring jdata = (* env)->NewStringUTF(env, "Hello Java!");
(* env)->CallVoidMethod(env, al_android_get_activity(), method_id, jdata);
(* env)->DeleteLocalRef(env, jdata);

look at that. C code talking to Java. iconic behavior, honestly 🌈


⭐ SINCE ⭐

this dropped in version 5.2.2 πŸŽ€

🚨 [Unstable API] β€” this API is brand new and subject to refinement. so like, it's still in its main character era and might get a glow-up later. don't build your whole personality around it being exactly like this forever, bestie 😭

and that's the whole page! slay πŸ’–

🌟 sign-off: this came from the Allegro reference manual, page al_android_get_jni_env(3alleg5). go forth and JNI, my friend 🧚✨
πŸ“¦ where this page comes from