I can figure out how to embed a unity project inside an Android project from articles on internet and Unity's own Learning section http://unity3d.com/learn. What I am having trouble with is communicating between Unity and Android. I need to send Unity some JSON data which will contain numbers and values to display and the URLs for a couple of images. From there on inside unity's scene I want to do some animation. Based on the selection made by the user, I need to send appropriate requests to our server and open different activities.
In normal Android development, I would pass information from one activity to another using Bundle, but I can't figure out how to do the same with Unity and Android. Getting user selection from Unity's scene to my application is also a problem that needs to be solved.
Unity game is not a normal Android app. It's more like a library integrated into an Android app.
Unity docs demonstrates that to call methods on Android native side from Unity you can use AndroidJavaClass (for Java class references and static calls) and AndroidJavaObject (for references to objects).
To interact the other way around you can use UnitySendMessage() in Java. The last parameter in UnitySendMessage() is an optional string argument that you can use to pass JSON to Unity.
In Unity you can either use JsonUtility.FromJson for deserialization or some 3rd party scripts for json parsing, there are a lot on github.
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