extern
"C"
JNIEXPORT jboolean JNICALL
Java_com_honeybadger_nativelib_NativeLib1_DoTestReflect(JNIEnv
*
env, jclass clazz) {
jclass jcTarget
=
env
-
>FindClass(
"com/honeybadger/nativelib/NativeLib1"
);
if
(jcTarget
=
=
nullptr) {
return
JNI_FALSE;
}
jmethodID mtdTarget
=
env
-
>GetStaticMethodID(jcTarget,
"TestReflect"
,
"(Ljava/lang/String;)Ljava/lang/String;"
);
if
(mtdTarget
=
=
nullptr) {
return
JNI_FALSE;
}
jstring jsArg
=
env
-
>NewStringUTF(
"来自于native的参数"
);
jstring jsResult
=
(jstring) env
-
>CallStaticObjectMethod(jcTarget, mtdTarget, jsArg);
const char
*
szResult
=
env
-
>GetStringUTFChars(jsResult, JNI_FALSE);
bool
bVerify
=
strcmp(szResult,
"ok"
)
=
=
0
;
env
-
>ReleaseStringUTFChars(jsArg, szResult);
return
bVerify;
}