From c8eee68f2a95c87f47cb832e21e8d8e0fd4a9f8b Mon Sep 17 00:00:00 2001 From: Hans Date: Wed, 23 Oct 2024 21:54:13 +0800 Subject: [PATCH] fix(Android): fix options type convert --- android/cpp-adapter.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/android/cpp-adapter.cpp b/android/cpp-adapter.cpp index 527918b..202dfa7 100644 --- a/android/cpp-adapter.cpp +++ b/android/cpp-adapter.cpp @@ -3,7 +3,6 @@ #include #include #include -#include template T get_map_value(JNIEnv *env, jobject params, const char *key) { @@ -11,12 +10,11 @@ T get_map_value(JNIEnv *env, jobject params, const char *key) { jmethodID get_method = env->GetMethodID( map_class, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); jobject value = env->CallObjectMethod(params, get_method, env->NewStringUTF(key)); - if constexpr (std::is_same_v) { - jclass float_class = env->FindClass("java/lang/Float"); - return env->CallFloatMethod(value, env->GetMethodID(float_class, "floatValue", "()F")); - } else if constexpr (std::is_same_v) { - jclass int_class = env->FindClass("java/lang/Integer"); - return env->CallIntMethod(value, env->GetMethodID(int_class, "intValue", "()I")); + jclass value_class = env->GetObjectClass(value); + if (env->IsSameObject(value_class, env->FindClass("java/lang/Double"))) { + return env->CallDoubleMethod(value, env->GetMethodID(value_class, "doubleValue", "()D")); + } else if (env->IsSameObject(value_class, env->FindClass("java/lang/Integer"))) { + return env->CallIntMethod(value, env->GetMethodID(value_class, "intValue", "()I")); } else { throw std::runtime_error("Unsupported type"); }