UnityCallAndroid.cs 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using UnityEngine;
  3. public class UnityCallAndroid : MonoBehaviour
  4. {
  5. private AndroidJavaObject RTKManager;
  6. void Start()
  7. {
  8. Func();
  9. }
  10. public void Func()
  11. {
  12. AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  13. AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
  14. try
  15. {
  16. RTKManager = new AndroidJavaObject("com.bxzzbdh.rtktest.RTK", jo);
  17. Debug.Log("RTK Has Been Called");
  18. }
  19. catch (Exception e)
  20. {
  21. Debug.LogError($"Func Expection{e}");
  22. }
  23. StartRtk();
  24. }
  25. public void StartRtk()
  26. {
  27. try
  28. {
  29. RTKManager.Call("StartRTK");
  30. }
  31. catch (Exception e)
  32. {
  33. Debug.LogError($"StartRTK Expection{e}");
  34. }
  35. }
  36. private void OnApplicationQuit()
  37. {
  38. RTKManager.Call("StopRTK");
  39. }
  40. }