using UnityEngine; using System.Collections; public class Example : MonoBehaviour { void Start () { AndroidJavaClass telephonyClass = new AndroidJavaClass ("android.telephony.TelephonyManager"); AndroidJavaObject telephonyInstance = telephonyClass.CallStatic("getDefault"); string deviceId = telephonyInstance.Call ("getDeviceId"); Debug.Log ("Device ID: " + deviceId); } }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { void Start () { AndroidJavaClass toastClass = new AndroidJavaClass ("android.widget.Toast"); AndroidJavaClass unityClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"); AndroidJavaObject unityActivity = unityClass.GetStaticIn this example, the AndroidJavaClass objects are created to represent the Toast and UnityPlayer classes in the android.widget and com.unity3d.player packages respectively. The GetStatic method is used to get the current Unity activity, and the CallStatic method is then used to create a new Toast instance and call the "makeText" static method to set the message text and duration. Finally, the show method is called on the toastInstance object to display the Toast message.("currentActivity"); AndroidJavaObject toastInstance = toastClass.CallStatic ("makeText", unityActivity, "Hello from Unity!", Toast.LENGTH_SHORT); toastInstance.Call ("show"); } }