using System; using UnityEngine; using System.Collections.Generic; public class AndroidDeviceInfo { private AndroidJavaObject jo; private AndroidJavaObject context; private static AndroidDeviceInfo _instance; public static AndroidDeviceInfo Instance { get { if (_instance == null) { _instance = new AndroidDeviceInfo(); } return _instance; } } private AndroidDeviceInfo() { using (var up = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { context = up.GetStatic("currentActivity"); using (var adi = new AndroidJavaClass("com.bluewhale.androidutils.AndroidDeviceInfo")) { jo = adi.CallStatic("instance"); jo.Call("Init", context); } } } public void DeviceInit() { Debug.Log("设备信息初始化"); } //设备机型类型 public string GetDeviceBrand() { string type = ""; try { type = jo.CallStatic("GetDeviceBrand"); } catch (Exception e) { Debug.LogError(e); } return type; } //设备机型名称 public string GetDeviceModel() { string type = ""; try { type = jo.CallStatic("GetDeviceModel"); } catch (Exception e) { Debug.LogError(e); } return type; } //设备系统版本号 public string GetSystemVersion() { string type = ""; try { type = jo.CallStatic("GetSystemVersion"); } catch (Exception e) { Debug.LogError(e); } return type; } //设备分辨率 public string GetScreenRatio() { string type = ""; try { type = jo.CallStatic("GetScreenRatio",context); } catch (Exception e) { Debug.LogError(e); } return type; } //设备运营商类型 public string GetOperatorName() { string type = ""; try { type = jo.CallStatic("GetOperatorName", context); } catch (Exception e) { Debug.LogError(e); } return type; } //设备网络状态 public string GetNetworkType() { string type = ""; try { type = jo.CallStatic("GetNetworkType", context); } catch (Exception e) { Debug.LogError(e); } return type; } //获取IP public string GetLocalIpAddress() { string type = ""; try { type = jo.CallStatic("GetLocalIpAddress", context); } catch (Exception e) { Debug.LogError(e); } return type; } //sdk 获取设备标识 public string GetDeviceID() { return jo.Call("GetDeviceID"); } //sdk 获取IMEI public string GetIMEICode() { return jo.Call("GetIMEICode"); } //暂时存放--复制粘贴功能(本不隶属于此) public void SetCopyValue(string str) { jo.CallStatic("CopyToClipBoard", str); } public string GetPastValue() { string result = ""; result = jo.CallStatic("PasteFromClipBoard", context); return result; } }