I've got a method:
public native void doSomething(ByteBuffer in, ByteBuffer out);
Generated by javah C/C++ header of this method is:
JNIEXPORT void JNICALL Java__MyClass_doSomething (JNIEnv *, jobject, jobject, jobject, jint, jint);
How can I get a data array from jobject (that is a ByteBuffer instance) ?
jobject NewGlobalRef(JNIEnv *env, jobject obj); Creates a new global reference to the object referred to by the obj argument. The obj argument may be a global or local reference.
JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).
Introduction to Java Native Interface: Establishing a bridge between Java and C/C++ JNI (Java Native Interface) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.
In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages ...
Assuming you allocated the ByteBuffer using ByteBuffer.allocateDirect() you can use GetDirectBufferAddress
jbyte* bbuf_in; jbyte* bbuf_out; bbuf_in = (*env)->GetDirectBufferAddress(env, buf1); bbuf_out= (*env)->GetDirectBufferAddress(env, buf2);
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