From bab1e388712597cfd16e9b47c5dc8d9840ea91e8 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期一, 09 三月 2020 17:39:09 +0800 Subject: [PATCH] 更新地图 --- lib/src/main/cpp/native-lib.cpp | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp index 8f18adf..69ef30e 100644 --- a/lib/src/main/cpp/native-lib.cpp +++ b/lib/src/main/cpp/native-lib.cpp @@ -225,9 +225,36 @@ } } -void DisplayText(const char *string) +void PlayTTS(const char *string) { - DEBUG("DisplayText: %s", string); + DEBUG("PlayTTS: %s", string); + + JNIEnv *env; + bool ready_in_java_env = false; + + if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) { + // Attach涓荤嚎绋� + if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) { + LOGE("%s: AttachCurrentThread() failed", __FUNCTION__); + return; + } + } else { + ready_in_java_env = true; + } + + jclass cls = env->GetObjectClass(sg_obj); + jmethodID fun = env->GetMethodID(cls, "TextSpeak", "(Ljava/lang/String;)V"); + + env->CallVoidMethod(sg_obj, fun, env->NewStringUTF(string)); + + env->DeleteLocalRef(cls); + + if (!ready_in_java_env) { + //Detach涓荤嚎绋� + if (sg_jvm->DetachCurrentThread() != JNI_OK) { + LOGE("%s: DetachCurrentThread() failed", __FUNCTION__); + } + } } extern "C" -- Gitblit v1.8.0