|
| 1 | +# Unity Android SDK Plugins Basic Utils |
| 2 | + |
| 3 | +This plugin provides basic Android util functions. |
| 4 | + |
| 5 | +## Plugin Functions/Features : |
| 6 | + |
| 7 | +- Show Android Toast UI/Popup (Short/Long) |
| 8 | +- Check if device has Internet connection |
| 9 | +- Check if device is connected to a WiFi |
| 10 | +- Check if WiFi is enabled on device |
| 11 | +- Check if Hotspot is enabled on device |
| 12 | +- Check if Bluetooth is enabled on device |
| 13 | +- Check if Developer Mode (USB debugging) is enabled |
| 14 | +- Check if Device is Rooted |
| 15 | +- Check if Device is Rooted or has any harmful app installed |
| 16 | +- Check if Location Service (GPS) is enabled |
| 17 | +- Get Android Device Id (Settings.Secure.ANDROID_ID or SSAID) |
| 18 | +- Get Current Device Battery Percentage |
| 19 | + |
| 20 | +## Plugin Usage : |
| 21 | + |
| 22 | +In your unity project, you can use these plugins in your C# scripts. |
| 23 | + |
| 24 | +### Common code required to access all functions |
| 25 | + |
| 26 | +``` |
| 27 | +const string pluginName = "com.arupakaman.pluginbasicutils.unity.UnityUtils"; // Constant of util static class location |
| 28 | +
|
| 29 | + AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| 30 | + AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); // jo will be used for Context param |
| 31 | + AndroidJavaClass ajc = new AndroidJavaClass(pluginName); // ajc will be used to access UnityUtils class |
| 32 | +``` |
| 33 | + |
| 34 | +### To show Android Toast UI/Popup (Short/Long) |
| 35 | + |
| 36 | +``` |
| 37 | + ajc.CallStatic("toast", jo, "Hello Unity World!"); // toast is function name to show the Toast |
| 38 | + ajc.CallStatic("toastLong", jo, "Hello Unity World!"); // for long toast |
| 39 | +``` |
| 40 | + |
| 41 | +### To check boolean returning functions |
| 42 | + |
| 43 | +``` |
| 44 | + bool isNetConnected = ajc.CallStatic<bool>("isNetConnected", jo); |
| 45 | + bool isWifiConnected = ajc.CallStatic<bool>("isWifiConnected", jo); |
| 46 | + bool isWifiEnabled = ajc.CallStatic<bool>("isWifiEnabled", jo); |
| 47 | + bool isHotspotEnabled = ajc.CallStatic<bool>("isHotspotEnabled", jo); |
| 48 | + bool isBluetoothEnabled = ajc.CallStatic<bool>("isBluetoothEnabled", jo); |
| 49 | + bool isDeveloperModeEnabled = ajc.CallStatic<bool>("isDeveloperModeEnabled", jo); |
| 50 | + bool isRooted = ajc.CallStatic<bool>("isRooted", jo); |
| 51 | + bool isRootedOrHarmfulAppsInstalled = ajc.CallStatic<bool>("isRootedOrHarmfulAppsInstalled", jo); |
| 52 | + bool isGpsEnabled = ajc.CallStatic<bool>("isGpsEnabled", jo); |
| 53 | +``` |
| 54 | + |
| 55 | +### To get Android Device ID |
| 56 | + |
| 57 | +``` |
| 58 | + string androidDeviceId = ajc.CallStatic<string>("getAndroidDeviceId", jo); |
| 59 | +``` |
| 60 | + |
| 61 | +### Current Device Battery Percentage |
| 62 | + |
| 63 | +``` |
| 64 | + int batteryPercentage = ajc.CallStatic<int>("getBatteryPercentage", jo); |
| 65 | +``` |
| 66 | + |
| 67 | +### I prefer a star than a cup of coffee |
0 commit comments