unity直接调用android toast

public class CommonUtil {

   static  AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
   static AndroidJavaObject currentActivity = UnityPlayer.GetStatic("currentActivity");
   static AndroidJavaObject context = currentActivity.Call("getApplicationContext");
 

    public static  void showToast(string content) {

        currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
            AndroidJavaClass Toast = new AndroidJavaClass("android.widget.Toast");
            AndroidJavaObject javaString = new AndroidJavaObject("java.lang.String", content);
            AndroidJavaObject toast = Toast.CallStatic("makeText", context, javaString, Toast.GetStatic("LENGTH_SHORT"));
            toast.Call("show");
        }
     ));

    }

    
}

 

你可能感兴趣的:(unity,移动开发,游戏,java)