I'm developing a plugin for Unity Android using JNI. I create the .jar file with my Java code, and then .so file with the c++ bridge. Everything works fine when I call my library from Unity side. So, my problem is that in several parts of my Java code, I need to access to the context of the main activity (UnityPlayer3d). I need a pointer to this activity to call the function GetApplicationContext().
How can I obtain this pointer? I think about passing the pointer from Unity to my Java class as a parameter, but first I have to get it in Unity side.
Here's some code to get the activity JNI style:
var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var unityActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
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