Quantcast
Channel: Questions in topic: "native plugin"
Viewing all articles
Browse latest Browse all 376

Native android plugin get UnityPlayer activity and context

$
0
0
Has anyone here worked with native android plugin for Unity? Was wondering if there was a way to get UnityPlayer Activity and Context from JNI_OnLoad on the native side, instead of passing from Unity C# as following: var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var activity = unityPlayer.GetStatic("currentActivity"); var context = activity.Call("getApplicationContext"); My equivalent conversion on native side looks like: jclass unityPlayer = LoadJClass(env,"com/unity3d/player/UnityPlayer"); CheckExceptionInJava(env); jfieldID fid = env->GetStaticFieldID(unityPlayer,"currentActivity","Landroid/app/Activity"); CheckExceptionInJava(env); jobject activity = env->GetStaticObjectField(unityPlayer,fid); jmethodID mid = env->GetMethodID((jclass)activity,"getApplicationContext","()Landroid/content/Context"); jobject context = env->CallObjectMethod(activity,mid); CheckExceptionInJava(env); However, at runtime getting: **java.lang.NoSuchFieldError: no type "Landroid/app/Activity" found and so no field "currentActivity" could be found in class "Lcom/unity3d/player/UnityPlayer;" or its superclasses**

Viewing all articles
Browse latest Browse all 376

Trending Articles