I have byte array in java class , and i want to pass that byte array to JNI C class, I am not able to access that array in JNI C, please help.
you need to declare the JNI function that receives the array like this (in Java):
private native void sendData(byte[] data);
you call the function like any other function:
sendData(buffer);
and then in your C code implement the function like this:
JNIEXPORT void JNICALL Java_com_packageXXX_yourClass_sendData( JNIEnv* env, jobject thiz, jbyteArray data);
read the array:
byte * cData = env->GetByteArrayElements(data, &isCopy);
and release:
env->ReleaseByteArrayElements(data, cData, JNI_ABORT);
the above code is C++. To make it work for C you need to pass the jni environement (env) as the first parameter of the function you are calling, like this:
(*env)->GetByteArrayElements(env,...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With