Jni What Is The Method Descriptor For Char [] (char Array)?
My JAVA class code snippet .I want to access getReg_chal() method from my C file using JNI: public char[] getReg_chal() { return reg_chal; } My C file doing some jni
Solution 1:
The method signature would be "()[C" .
You can read about the details here and here.
To call the method using the method id, you'd just write something like
jobject obj = ... // This is the object you want to call the method on
jcharArray arr = (jcharArray) (*env)->CallObjectMethod(env, obj, mid);
int count = (*env)->GetArrayLength(env, arr);
jchar* chars = (*env)->GetCharArrayElements(env, arr, 0);
// Here, "chars" is a C pointer to an array of "count" characters. It's NOT// going to be 0-terminated, so be careful! Here's where you would do your// logging or whatever. One possible way to do this is by turning the `jchar`// array into a proper 0-terminated character string:
char * message = malloc(count + 1);
memcpy(message, chars, count);
message[count] = 0;
LOGD("NDK:LC: [%s]", message);
// When you're done you must call this!
(*env)->ReleaseCharArrayElements(env, arr, chars, 0);
Post a Comment for "Jni What Is The Method Descriptor For Char [] (char Array)?"