AndroidJavaObject jo = new AndroidJavaObject("android.content.res.Configuration");
jo.Call("setToDefaults");
2.带有返回值的普通方法
AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some string");
int hash = jo.Call<int>("hashCode");
3.没有返回值的静态方法
AndroidJavaObject jo = new AndroidJavaObject("android.os.Binder");
jo.CallStatic("flushPendingCommands");
4.带有返回值的静态方法
AndroidJavaObject jo = new AndroidJavaObject("java.lang.String");
string valueString = jo.CallStatic<string>("valueOf", 42.0);
我们往游戏对象上绑定一些操作–Operate.cs :
using UnityEngine;
using System.Collections;
public class Operate : MonoBehaviour
{
public Transform target;
public UILabel label;
public bool flag = true;
/// <summary>
/// 定义旋转速度
/// </summary>
public float RotateSpeed=45;
// Use this for in itialization
void Start ()
{
//Debug.Log("hello");
this.name = "Manager";
GetData ();
}
/// <summary>
/// 通过调用android中的方法获取name,并为label赋值
/// </summary>
void GetData()
{
AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
string name = jo.Call <string>("getName", "成功调用android方法");