using UnityEditor;
using UnityEngine;
using UnityEngine.Android;
public class AndroidK: MonoBehaviour
{
private AndroidJavaObject androidDebugBridge;
void Start()
{
androidDebugBridge = new AndroidJavaObject("android.os.Build");
#if UNITY_ANDROID
IsDeveloperModeEnabled();
#endif
}
//此处加是否处于开发者模式的代码
public void IsDeveloperModeEnabled()
{
// 获取设备的调试状态
AndroidJavaClass androidDebugBridge = new AndroidJavaClass("android.provider.Settings$Global");
AndroidJavaObject androidContext = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
string devSettings = androidDebugBridge.CallStatic<string>("getString", androidContext.Call<AndroidJavaObject>("getContentResolver"), "development_settings_enabled");
// 判断设备是否处于开发者模式
if (devSettings == "1")
{
//弹窗代码
Debug.Log("设备处于开发者模式");
}
else
{
Debug.Log("设备未处于开发者模式");
}
}
unity检测安卓手机是否处于开发者模式
于 2024-07-18 21:49:01 首次发布