miduo_client/Assets/LuaFramework/Scripts/SDK/Tools/AndroidDeviceInfo.cs

164 lines
3.6 KiB
C#

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