Add gioui.org/permission/bluetooth and EnableBluetooth() function.
This commit is contained in:
parent
820186e132
commit
4e4c071697
|
@ -3,6 +3,7 @@ package ble
|
|||
import (
|
||||
"log"
|
||||
"gioui.org/app"
|
||||
_ "gioui.org/permission/bluetooth"
|
||||
)
|
||||
|
||||
/*
|
||||
|
|
|
@ -27,6 +27,42 @@ SetLoader(JNIEnv* env, jobject context) {
|
|||
gFindClassMethod = (*env)->GetMethodID(env, lclass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
}
|
||||
|
||||
jclass
|
||||
FindClass(JNIEnv* env, char* name) {
|
||||
jstring strClassName = (*env)->NewStringUTF(env, name);
|
||||
return (*env)->CallObjectMethod(env, gClassLoader, gFindClassMethod, strClassName);
|
||||
}
|
||||
|
||||
void
|
||||
EnableBluetooth(JNIEnv* env, jobject ctx, jobject ad) {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "Finding BleUtil");
|
||||
jclass cls = FindClass(env, "st/wow/git/ble/BleUtil");
|
||||
if (cls == NULL) {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "not found");
|
||||
return;
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "getting <init>");
|
||||
jmethodID mid = (*env)->GetMethodID(env, cls, "<init>", "()V");
|
||||
if (mid == NULL) {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "not found");
|
||||
return;
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "calling NewObject");
|
||||
jobject bleutil = (*env)->NewObject(env, cls, mid);
|
||||
if (bleutil == NULL) {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "failed");
|
||||
return;
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "Getting Enable()");
|
||||
mid = (*env)->GetMethodID(env, cls, "Enable", "(Landroid/content/Context;)V");
|
||||
if (mid == NULL) {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "failed");
|
||||
return;
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "Calling Enable()");
|
||||
(*env)->CallVoidMethod(env, bleutil, mid, ctx);
|
||||
}
|
||||
|
||||
jobject
|
||||
GetBluetoothAdapter(JNIEnv* env, jobject ctx) {
|
||||
jclass cls = (*env)->GetObjectClass(env, ctx);
|
||||
|
@ -70,7 +106,10 @@ GetBluetoothAdapter(JNIEnv* env, jobject ctx) {
|
|||
} else {
|
||||
__android_log_write(ANDROID_LOG_DEBUG, "gio", "GetBluetoothAdapter(): Found");
|
||||
}
|
||||
|
||||
ad = (*env)->NewGlobalRef(env, ad);
|
||||
|
||||
EnableBluetooth(env, ctx, ad);
|
||||
return ad;
|
||||
}
|
||||
|
||||
|
@ -89,12 +128,6 @@ GetObjectStaticStringField(JNIEnv* env, jobject obj, char* fld) {
|
|||
return (jstring)(*env)->GetStaticObjectField(env, cls, id);
|
||||
}
|
||||
|
||||
jclass
|
||||
FindClass(JNIEnv* env, char* name) {
|
||||
jstring strClassName = (*env)->NewStringUTF(env, name);
|
||||
return (*env)->CallObjectMethod(env, gClassLoader, gFindClassMethod, strClassName);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject
|
||||
CreateObject(JNIEnv* env, jclass cls) {
|
||||
jmethodID init = (*env)->GetMethodID(env, cls, "<init>", "()V");
|
||||
|
@ -178,7 +211,7 @@ func JniCallVoidMethod(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID) {
|
|||
}
|
||||
|
||||
func JniCallBooleanMethod(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID) bool {
|
||||
return C.CallBooleanMethod(env, obj, methodID) == 0
|
||||
return C.CallBooleanMethod(env, obj, methodID) == C.JNI_TRUE
|
||||
}
|
||||
|
||||
func JniCallIntMethod(env *C.JNIEnv, obj C.jobject, methodID C.jmethodID) int {
|
||||
|
|
Loading…
Reference in New Issue
Block a user