Create NewDirectByteBuffer using integrated Unity JNI tools?

My application requires that I create a ByteBuffer through JNI.
To do this I am currently using the JNI *.so provided by one of the Unity Android plugin examples.
My C# code is as follows:

mGlobalPtr = Marshal.AllocHGlobal(buffer.Length);
JavaVM.AttachCurrentThread();
mByteBuffer = JNI.NewGlobalRef(JNI.NewDirectByteBuffer(mGlobalPtr,(long)buffer.Length))

My question is: now that Unity has integrated JNI classes for most JNI functions is there a way for me to use those tools to create call the JNI NewDirectByteBuffer() method without having to utilize this additonal JNI library?

If i understood that right you’re currently using an additional JNI library?

It’s not entirely clear for what you need that native array, but in Unity you can use AndroidJNI.NewByteArray to allocate a native byte array of the specified size.

You may want to have a look at the other methods that are provided inside the AndroidJNI class. There’s also the AndroidJNIHelper class, but it mainly contains helpers to construct parameter arrays for method calls. Those are used by the wrapper classes “AndroidJavaClass” and “AndroidJavaObject”.