My java class has a static function defined as follows:
public static void logEvent(final String eventName, final String jObject) {
//Function data
}
Now my cpp file has the following function
void PingoScreen::callApslarIntegration(){
char* eventName="bingo";
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/myapp/test/ApslarSetup","logEvent", "()V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}
How can i send two string params to the JAVA function via JNI ?
Kind Regards
===============================================================
void PingoScreen::callApsIntegration() {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/myapp/test/ApslarSetup",
"logJSONEvent", "()V")) {
const char* cstr1 = "Test1";
const char* cstr2 = "Test2";
jstring jstr1 = t.env->NewStringUTF(cstr1);
jstring jstr2 = t.env->NewStringUTF(cstr2);
t.env->CallStaticVoidMethod(t.classID, t.methodID,jstr1,jstr2);
t.env->DeleteLocalRef(t.classID);
}
}
The above function causes a crash ?
==================================
Finally got it to work
void PingoScreen::callApslarIntegration() {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo
(t, "com/nbs/test/ApslarSetup",
"logJSONEvent",
"(Ljava/lang/String;Ljava/lang/String;)V")) {
const char* cstr1 = "Test1";
const char* cstr2 = "Test2";
jstring jstr1 = t.env->NewStringUTF(cstr1);
jstring jstr2 = t.env->NewStringUTF(cstr2);
t.env->CallStaticVoidMethod(t.classID, t.methodID,jstr1,jstr2);
t.env->DeleteLocalRef(t.classID);
}
}
The crash was due to the line
if (JniHelper::getStaticMethodInfo
(t, "com/nbs/test/ApslarSetup",
"logJSONEvent",
"(Ljava/lang/String;Ljava/lang/String;)V"))
The signiture had to be Ljava/lang/String;Ljava/lang/String; and not Ljava/lang/String;Ljava/lang/String (notice the last semi-colon)
javap -s -public com.nbs.test.ApslarSetup | egrep -A 2 "logJSONEvent"to obtain signatures to use with JNI.