godot-ultraleap-plugin/src/binder.cpp

31 lines
1.3 KiB
C++

#include "binder.h"
#ifdef ANDROID_ENABLED
#include <jni.h>
Binder::Binder(JNIEnv *env) {
class_binder = env->FindClass("com/ultraleap/tracking/service_binder/ServiceBinder");
// Really not sure here
jmethodID constructor = env->GetMethodID(class_binder, "<init>", "(Landroid/content/Context;Z)V");
binder_object = env->NewObject(class_binder, constructor, get_global_context(env), false);
bind_method = env->GetMethodID(class_binder, "bind", "()Z");
unbind_method = env->GetMethodID(class_binder, "unbind", "()V");
is_bound_method = env->GetMethodID(class_binder, "isBound", "()I");
}
jobject Binder::get_global_context(JNIEnv *env) {
jclass activityThread = env->FindClass("android/app/ActivityThread");
jmethodID currentActivityThread = env->GetStaticMethodID(activityThread, "currentActivityThread", "()Landroid/app/ActivityThread;");
jobject at = env->CallStaticObjectMethod(activityThread, currentActivityThread);
jmethodID getApplication = env->GetMethodID(activityThread, "getApplication", "()Landroid/app/Application;");
jobject context = env->CallObjectMethod(at, getApplication);
return context;
}
void Binder::bind(JNIEnv *env) {
jobject status = env->CallObjectMethod(binder_object, bind_method);
}
#endif