Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AndroidJavaProxy

Namespace: UnityEngine

Description

This class can be used to implement any java interface. Any java vm method invocation matching the interface on the proxy object will automatically be passed to the c# implementation.

// Opens an android date picker dialog and grabs the result using a callback.

// Dummy class to hold date - makes it easier to modify it in the callback class SelectedDate { static var date : Date = System.DateTime.Now; }

// The callback class class DateCallback extends AndroidJavaProxy { function DateCallback() { super("android.app.DatePickerDialog$OnDateSetListener"); } function onDateSet(view: AndroidJavaObject, year: int, monthOfYear: int, dayOfMonth: int){ SelectedDate.date = new Date(year, monthOfYear + 1, dayOfMonth); } }

function OnGUI () { if (GUI.Button (Rect (10,10,450,100), String.Format("{0:yyyy-MM-dd}", SelectedDate.date))) { var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic.<AndroidJavaObject>("currentActivity"); activity.Call("runOnUiThread", new AndroidJavaRunnable(function(){ new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), SelectedDate.date.Year, SelectedDate.date.Month - 1, SelectedDate.date.Day).Call("show"); })); } }

Variables

javaInterface Java interface implemented by the proxy.

Constructors

AndroidJavaProxy

Functions

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 invokation, 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.