Attempt at using the binder but I couldn't build
This commit is contained in:
parent
c6fec9e64b
commit
b2cb023ddf
31
src/binder.cpp
Normal file
31
src/binder.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#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
|
26
src/binder.h
Normal file
26
src/binder.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef BINDER_HPP
|
||||
#define BINDER_HPP
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
#include <jni.h>
|
||||
|
||||
class Binder {
|
||||
private:
|
||||
jclass class_binder;
|
||||
jobject binder_object;
|
||||
|
||||
jmethodID bind_method;
|
||||
jmethodID unbind_method;
|
||||
jmethodID is_bound_method;
|
||||
|
||||
static jobject get_global_context(JNIEnv *env);
|
||||
public:
|
||||
Binder(JNIEnv* env);
|
||||
~Binder() {}
|
||||
|
||||
void bind(JNIEnv *env);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -16,6 +16,11 @@
|
|||
#include "frame.h"
|
||||
#include "allocator.h"
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
#include <jni.h>
|
||||
#include "binder.h"
|
||||
#endif
|
||||
|
||||
using namespace godot;
|
||||
|
||||
UltraleapHandTracking::~UltraleapHandTracking() {
|
||||
|
@ -218,6 +223,21 @@ void UltraleapHandTracking::_bind_methods() {
|
|||
|
||||
void UltraleapHandTracking::start() {
|
||||
UtilityFunctions::print("Starting the tracking");
|
||||
|
||||
#ifdef ANDROID_ENABLED
|
||||
// Acquire a pointer to the current JavaVM
|
||||
jsize jvmBufferLength = 1; // At most vmBufLength number of entries ill be written for the list of returned JavaVMs
|
||||
jsize jvmTotalNumberFound = 0; // The total number of JavaVMs found
|
||||
JavaVM jvmBuffer[jvmBufferLength]; // Array of JavaVMs
|
||||
JavaVM * pjvmBuffer = jvmBuffer; // Pointer to array of JavaVMs
|
||||
jint result = JNI_GetCreatedJavaVMs(&pjvmBuffer, jvmBufferLength, &jvmTotalNumberFound); // Get all created JavaVMs
|
||||
|
||||
JNIEnv *env;
|
||||
pjvmBuffer->AttachCurrentThread(&env, 0);
|
||||
Binder* service_binder = new Binder(env);
|
||||
service_binder->bind(env);
|
||||
#endif
|
||||
|
||||
LEAP_CONNECTION_CONFIG config;
|
||||
|
||||
// Set connection to multi-device aware
|
||||
|
|
Loading…
Reference in a new issue