AndroidJNIClass unable to excute my non-static function

前端 未结 1 1102
抹茶落季
抹茶落季 2021-01-14 03:20

i have calling java function from my unity code. I have both static & non-static type of functions in my java class To access first static function, i u

相关标签:
1条回答
  • use your "activity" variable for non-static calls: activity.Call("Enable", qwe); There is example of static and non-static functions calls:

    public class Caller {
      private readonly AndroidJavaClass _ActivityClass;
      private readonly AndroidJavaObject _ActivityObject;
      private readonly AndroidJavaClass _MyActivityClass; 
    
      public Caller() {
        _ActivityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        _MyActivityClass = new AndroidJavaClass("com.example.u2aTest.MyMainActivity"); 
    
        _ActivityObject = _ActivityClass.GetStatic("currentActivity");
        // AndroidJavaObject my_activity_object = _MyActivityClass.GetStatic("currentActivity"); //doesn't work
      }
    
      public void MakeTestCalls() {
        _ActivityObject.Call("testVoid"); // works fine
        //_ActivityClass.CallStatic("testVoidStatic"); // doesn't works
       _MyActivityClass.CallStatic("testVoidStatic"); // works fine
        //_ActivityObject.CallStatic("testVoid"); // doesn't work on some divices
    
       //public int testInt(int intValue)
       int iresult = _ActivityObject.Call<int>("testInt", 999);
    
       //public String testStringString(String paramValue)
       String sresult = _ActivityObject.Call<String>("testStringString", "s2");      
    
       //public static int testIntStatic(int intValue) 
       iresult = _MyActivityClass.CallStatic<int>("testIntStatic", 999);
    
       //public static String testStringStringStatic(String paramValue)
       sresult =_MyActivityClass.CallStatic<String>("testStringStringStatic", "s1");
      }
    }
    

    Take a look on example of Android plugin for Unity3D for detailes.

    0 讨论(0)
提交回复
热议问题