Skip to content

Commit a55403e

Browse files
committed
start doing jni stuff directly from cython for bluetooth
1 parent bd21d63 commit a55403e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

recipes/android/src/android.pyx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# probably not enought
2+
cdef extern from "jni.h":
3+
JNIEnv *SDL_ANDROID_GetJNIEnv(void)
4+
15
# Android-specific python services.
26

37
cdef extern int SDL_ANDROID_CheckPause()
@@ -246,3 +250,31 @@ class AndroidBrowser(object):
246250
import webbrowser
247251
webbrowser.register('android', AndroidBrowser, None, -1)
248252

253+
254+
# -------------------------------------------------------------------
255+
# Bluetooth
256+
cdef class Bluetooth(object):
257+
cdef JNIEnv *j_env = SDL_ANDROID_GetJNIEnv()
258+
cdef jclass *j_class = *j_env->FindClass(j_env,
259+
"org/renpy/android/BluetoothConnection")
260+
261+
cdef __init__(self):
262+
constructor = j_env->GetMethod(j_env, j_class, "<init>", "(C)V")
263+
self._jself = j_env->NewObject(j_env, j_class, constructor)
264+
265+
cdef void setUUID(self, uuid):
266+
j_method = j_env->GetMethod(j_env, j_class,
267+
"setUUID",
268+
"(Ljava/lang/String;)V")
269+
270+
j_env->CallVoidMethod(
271+
j_env, j_class, self._jself, j_method,
272+
j_env->NewStringUTF(uuid))
273+
274+
cdef getUUID(self):
275+
j_method = j_env->GetMethod(j_env, j_class,
276+
"getUUID",
277+
"()Ljava/lang/String;")
278+
279+
return j_env->GetStringUTFChars(j_env->CallStringMethod(
280+
j_env, j_class, self._jself, j_method))

0 commit comments

Comments
 (0)