Two methods are summarized, for reference.
Method One
(To write a method under the Unityplayeractivity class, otherwise it cannot be called):
1 //Get class2 3Androidjavaclass JC =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer");4 5 6 7 //Get Java Objects8 9Androidjavaobject Jo = JC. Getstatic<androidjavaobject> ("currentactivity");Ten One A - //Execution Method - theJo. Call ("Method", ARG); - -
Method Two:
1 //JNI Create a new thread2 3 Androidjni.attachcurrentthread ();4 5 6 7 //Get class8 9IntPtr CLS = Androidjni.findclass ("Com/unity3d/player/unityplayer");Ten OneINTPTR FID = Androidjni.getstaticfieldid (CLS,"currentactivity","landroid/app/activity;"); A -IntPtr obj =Androidjni.getstaticobjectfield (CLS, FID); - the - - //Get class - +IntPtr Cls_ourappactitvityclass = Androidjni.findclass ("Com/bodhi/talkingbodhi"); - + A at //How to obtain - -IntPtr Enablemethod = Androidjni.getmethodid (Cls_ourappactitvityclass,"enableads","V"); - - - in //If the method exists, execute the - to if(Androidjni.isinstanceof (obj, cls_ourappactitvityclass)! =false) { + -jvalue[] MyArray =Newjvalue[1]; the * Androidjni.callvoidmethod (obj, Enablemethod, myArray); $ Panax Notoginseng}
Two ways Unity calls Android