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() { #if UNITY_IOS #elif UNITY_ANDROID 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); } } #endif } public void DeviceInit() { Debug.Log("设备信息初始化"); } //设备机型类型 public string GetDeviceBrand() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetDeviceBrand"); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //设备机型名称 public string GetDeviceModel() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetDeviceModel"); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //设备系统版本号 public string GetSystemVersion() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetSystemVersion"); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //设备分辨率 public string GetScreenRatio() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetScreenRatio",context); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //设备运营商类型 public string GetOperatorName() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetOperatorName", context); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //设备网络状态 public string GetNetworkType() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetNetworkType", context); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //获取IP public string GetLocalIpAddress() { string type = ""; try { #if UNITY_IOS #elif UNITY_ANDROID type = jo.CallStatic("GetLocalIpAddress", context); #endif } catch (Exception e) { Debug.LogError(e); } return type; } //sdk 获取设备标识 public string GetDeviceID() { #if UNITY_IOS return ""; #elif UNITY_ANDROID return jo.CallStatic("GetDeviceID"); #else return ""; #endif } //sdk 获取IMEI public string GetIMEICode() { #if UNITY_IOS return ""; #elif UNITY_ANDROID return jo.CallStatic("GetIMEICode"); #else return ""; #endif } //sdk 获取app名 public string GetAppName() { #if UNITY_IOS return ""; #elif UNITY_ANDROID return jo.CallStatic("getAppName"); #else return ""; #endif } //sdk 获取版本名称 public string GetVersionName() { #if UNITY_IOS return ""; #elif UNITY_ANDROID return jo.CallStatic("getVersionName"); #else return ""; #endif } //sdk 获取版本号 public int GetVersionCode() { #if UNITY_IOS return 0; #elif UNITY_ANDROID return jo.CallStatic("getVersionCode"); #else return 0; #endif } //sdk 获取包名 public string GetPackageName() { #if UNITY_IOS return ""; #elif UNITY_ANDROID return jo.CallStatic("getPackageName"); #else return ""; #endif } //暂时存放--复制粘贴功能(本不隶属于此) public void SetCopyValue(string str) { #if UNITY_IOS #elif UNITY_ANDROID jo.CallStatic("CopyToClipBoard", str); #else #endif } public string GetPastValue() { string result = ""; #if UNITY_IOS #elif UNITY_ANDROID result = jo.CallStatic("PasteFromClipBoard", context); #else #endif return result; } }