このクラスを使用して任意の Java インターフェースの実装できます。プロキシオブジェクト上のインターフェースに一致する任意の Java VM メソッド実行は C# 実装に自動的に渡されます。
Note: this API can be used from custom thread, but requires that thread to be attached to JVM first, see AndroidJNI.AttachCurrentThread.
// Opens an android date picker dialog and grabs the result using a callback. using UnityEngine; using System;
class ExampleClass : MonoBehaviour { private static DateTime selectedDate = DateTime.Now;
class DateCallback : AndroidJavaProxy { public DateCallback() : base("android.app.DatePickerDialog$OnDateSetListener") {} void onDateSet(AndroidJavaObject view, int year, int monthOfYear, int dayOfMonth) { selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth); } }
void OnGUI() { if (GUI.Button(new Rect(15, 15, 450, 75), string.Format("{0:yyyy-MM-dd}", selectedDate))) { AndroidJavaClass activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaClass>("currentActivity"); activity.Call("runOnUiThread", new AndroidJavaRunnable(() => { new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), selectedDate.Year, selectedDate.Month - 1, selectedDate.Day).Call("show"); })); } } }
javaInterface | プロキシにより実装された Java インターフェース。 |
AndroidJavaProxy |
equals | The equivalent of the java.lang.Object equals() method. |
hashCode | The equivalent of the java.lang.Object hashCode() method. |
Invoke | Called by the java vm whenever a method is invoked on the java proxy interface. You can override this to run special code on method invocation, or you can leave the implementation as is, and leave the default behavior which is to look for c# methods matching the signature of the java method. |
toString | The equivalent of the java.lang.Object toString() method. |