Skip to content

Commit

Permalink
Add android debugging mode checker . .
Browse files Browse the repository at this point in the history
  • Loading branch information
krlan2789 authored Jul 29, 2024
1 parent e84a58b commit 9e4bfc8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
44 changes: 15 additions & 29 deletions Runtime/Android/UnityActivityJavaClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<int>("getInt", CurrentActivity.Call<AndroidJavaObject>("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);
}
Expand Down Expand Up @@ -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<AndroidJavaObject>("put", item, false);
// }
// AndroidJavaObject resultContract = ACTIVITY_RESULT_CONTRACTS_CLASS.CallStatic<AndroidJavaObject>("RequestMultiplePermissions");
// var launcher = CurrentActivity.Call<AndroidJavaObject>("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<AndroidJavaObject>("makeText", CurrentActivity, message, 0);
// toast.Call("show");
// }));
//}
#endif
}
}
39 changes: 19 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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": "[email protected]",
"url": "https://erlankurnia.github.io"
}
}

0 comments on commit 9e4bfc8

Please sign in to comment.