I read a lot of examples to retrieve a java string in C/C++ code, but it seems that I miss something. this simple code doesn't work..
In ActivityTest (android java code) I've:
public static native void nativeInit(String stringfromjava);
In TestActivity I've:
ActivityTest.nativeInit("test");
and in my test-jni.c:
JNIEXPORT void JNICALL Java_com_test_jni_ActivityTest_nativeInit(JNIEnv* env, jclass cls, jobject obj, jstring stringfromjava){
__android_log_print(ANDROID_LOG_INFO, "TESTJNI","Native Init started");
const char* w_buf = (*env)->GetStringUTFChars(env, stringfromjava, 0);
if(w_buf == NULL) {
__android_log_print(ANDROID_LOG_INFO, "TESTJNI","file path recv nothing");
}
else {
__android_log_print(ANDROID_LOG_INFO, "TESTJNI","String: %s", w_buf);
}
(*env)->ReleaseStringUTFChars(env, stringfromjava, w_buf);
}
But in my logcat I get only:
I/TESTJNI (18921): Native Init started
I/TESTJNI (18921): String:
Where I'm wrong...?
FIXED Thanks to Mario, removing "jobject obj" from the signature fixed my issue!