From 9e4bfc862abd2746a3bf1676399ea3498caa8874 Mon Sep 17 00:00:00 2001 From: Erlan Kurnia <33871129+krlan2789@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:56:41 +0700 Subject: [PATCH] Add android debugging mode checker . . --- Runtime/Android/UnityActivityJavaClass.cs | 44 ++++++++--------------- package.json | 39 ++++++++++---------- 2 files changed, 34 insertions(+), 49 deletions(-) diff --git a/Runtime/Android/UnityActivityJavaClass.cs b/Runtime/Android/UnityActivityJavaClass.cs index 493e329..b241ccb 100644 --- a/Runtime/Android/UnityActivityJavaClass.cs +++ b/Runtime/Android/UnityActivityJavaClass.cs @@ -22,8 +22,9 @@ public static class UnityActivityJavaClass public static readonly AndroidJavaClass VERSION_INFO_CLASS = new("android.os.Build$VERSION"); public static readonly AndroidJavaClass UNITY_PLAYER_CLASS = new("com.unity3d.player.UnityPlayer"); public static readonly AndroidJavaClass PACKAGE_MANAGER_CLASS = new("android.content.pm.PackageManager"); - //public static readonly AndroidJavaClass ACTIVITY_RESULT_LAUNCHER_CLASS = new("androidx.activity.result.ActivityResultLauncher"); - //public static readonly AndroidJavaClass ACTIVITY_RESULT_CONTRACTS_CLASS = new("androidx.activity.result.contract.ActivityResultContracts"); + //public static readonly AndroidJavaClass SETTINGS_CLASS = new("android.provider.Settings"); + //public static readonly AndroidJavaClass SETTINGS_SECURE_CLASS = new("android.provider.Settings$Secure"); + public static readonly AndroidJavaClass SETTINGS_GLOBAL_CLASS = new("android.provider.Settings$Global"); public static readonly string INTENT_CLASS_PATH = "android.content.Intent"; public static readonly string COMPONENT_NAME_CLASS_PATH = "android.content.ComponentName"; @@ -67,6 +68,18 @@ public static string PackageName { } } + public static bool IsDebuggingModeEnabled + { + get + { + // Check if developer options are enabled + bool status = SETTINGS_GLOBAL_CLASS.CallStatic("getInt", CurrentActivity.Call("getContentResolver"), "adb_enabled", 0) == 1; + + Debug.Log($"Developer options are {(status ? "enabled" : "disabled")}!"); + return status; + } + } + public static AndroidJavaObject CreateIntent(string packangeName) { return new AndroidJavaObject(INTENT_CLASS_PATH, packangeName); } @@ -141,33 +154,6 @@ public static void OpenGPSSetting() Debug.LogWarning("GPS service disabled by user"); } - - //public static void RequestPermissions(string[] permissions) - //{ - // if (Application.isFocused) - // { - // //CurrentActivity.Call(REQUEST_PERMISSIONS_METHOD, permissions, 201); - - // AndroidJavaObject perms = new("java.util.HashMap"); - // foreach (var item in permissions) - // { - // perms.Call("put", item, false); - // } - // AndroidJavaObject resultContract = ACTIVITY_RESULT_CONTRACTS_CLASS.CallStatic("RequestMultiplePermissions"); - // var launcher = CurrentActivity.Call("registerForActivityResult", resultContract); - - // launcher.Call("launch", perms); - // } - //} - - //public static void ShowToast(string message) - //{ - // CurrentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => - // { - // AndroidJavaObject toast = new AndroidJavaClass("android.widget.Toast").CallStatic("makeText", CurrentActivity, message, 0); - // toast.Call("show"); - // })); - //} #endif } } \ No newline at end of file diff --git a/package.json b/package.json index c3fbb62..f41306f 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,21 @@ { - "name": "com.lan.live-location", - "version": "1.0.1", - "displayName": "Live Location", - "description": "A plugin that allow unity (Android) to run a background service location", - "unity": "2020.3", - "dependencies": {}, - "documentationUrl": "https://github.com/krlan2789/Unity-Background-Location/blob/main/README.md", - "keywords": [ - "android", - "mobile", - "background service", - "live location", - "background location", - "gps" - ], - "author": { - "name": "Erlan Kurnia", - "email": "erlank2789@gmail.com", - "url": "https://erlankurnia.github.io" - } + "name": "com.lan.live-location", + "version": "1.1.0", + "displayName": "Live Location", + "description": "A plugin that allow unity (Android) to run a background service location", + "unity": "2020.3", + "documentationUrl": "https://github.com/krlan2789/Unity-Background-Location/blob/main/README.md", + "keywords": [ + "android", + "mobile", + "background service", + "live location", + "background location", + "gps" + ], + "author": { + "name": "Erlan Kurnia", + "email": "erlank2789@gmail.com", + "url": "https://erlankurnia.github.io" + } } \ No newline at end of file