public GroupPlayDataListener() : base("com.your.library.IDataListener") {}
// The issue appears while passing back byte array from android to c#
// Please note that changing byte[] to string will work fine.
// I'm not sure about other array types.
public void onDataReceived(string source, byte[] data) {
Debug.Log(source);
}
}
...
// Here we call an method from java that sets the listener
activity.Call<int>("someMethod", newGroupPlayDataListener());
It will produce the following result:
Basically if you try to pass back byte array to your unity logic it will crash since it won’t be able to find getLength method (it is looking for a non-static getLength(byte[ ]) method, from Android source it seems that it’s a static getLength(Object)).
Sending byte[ ] (byte array) from Unity to Droid works without problem, Droid to Unity 4.5 NOT. CONFIRMED. So create wrapper object around your byte[ ] on Droid side:
package ws.winx.hid;
public class ReadData {
public byte[] Buffer;
public ReadData(byte[] buffer) {
Buffer=buffer;
}
}
....
listener.onYourFunctionNameInsideProxy(new ReadData(someByteArray));
Why this is not auto? Unity team should answer as most of the transfer anywhere is byte[ ] based.
Also be carefully that Java byte is signed (-128 to 127) and C# byte is (0 to 255) not signed (use sbyte C#)
Hi,
First of all thank you for the response and sorry for my late reply.
For the people who are facing the same issues, the workaround proposed by Winxlex works perfect.
Thank you for the support!
So for Unity versions that are newer than 4.5, wrappers like this ^ are no longer needed? I’m also using a byte array in c# passing that to java by doing AndroidJavaClass(“com.class.name”).CallStatic(“javaFunctionName”, byte);
I am currently facing this issue with AndroidJavaProxy with java String[ ] and java int[ ] to .Net string[ ] and int[ ]. When I run adb logcat I can see it’s an issue with com.unity3d.player.RefelectionHelper that is raising this exception. It doesn’t cause a crash but my AndroidJavaProxy object never gets called for that specific method that is expecting a string[ ] coming from Android’s side.
I also tried to change my method signature from
myMethod(string[ ] param1, int[ ] param2) to myMethod(AndroidJavaObject param1, AndroidJavaObject param2) so that I could use the AndroidJNIHelper and convert it myself. This doesn’t work since the method never gets invoked. Is there a way around this?