The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Converting a byte[] from java (JNI) to pass to NDK

2013-07-14 09:19:17


I'd like to use the native library for Android, and i'd like to pass some data from Java to the native library.

The data i'd like to pass is a byte array (byte[])

I define a JNI native method like so:

JNIEXPORT void JNICALL Java_demo_android_loadBalancing_PhotonNetworkingProvider_raiseEvent(JNIEnv* env, jobject obj, jbyte eventCode, jboolean reliable, jbyteArray data)

A jbyteArray can be converted into a byte array (byte*), however the Photon Cloud library works internally with a nByte type which is incompatible.

How can i properly pass a byte array into the library (to be wrapped as data inside a Hashtable that will be sent in an event) ?



2013-07-15 13:30:15

nByte is defined as unsigned char, which matches the C# byte on the server side, which is unsigned, too In you JNI function just cast the byte* to nByte*.

Back to top