// https://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID /// <summary> /// A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device. /// The value may change if a factory reset is performed on the device. /// </summary> /// <returns>The unique identifier of the device.</returns> public static string GetAndroidId() { if (AGUtils.IsNotAndroidCheck()) { return(string.Empty); } try { using (var objResolver = AGUtils.Activity.CallAJO("getContentResolver")) { using (var clsSecure = new AndroidJavaClass("android.provider.Settings$Secure")) { string ANDROID_ID = clsSecure.GetStaticStr("ANDROID_ID"); string androidId = clsSecure.CallStaticStr("getString", objResolver, ANDROID_ID); return(androidId); } } } catch (Exception e) { Debug.LogWarning("Failed to get Android Id, reasong: " + e.Message); return(string.Empty); } }
private static string GetBuildClassStaticStr(string fieldName) { if (AGUtils.IsNotAndroidCheck()) { return(string.Empty); } try { using (var version = new AndroidJavaClass(BuildClass)) { return(version.GetStaticStr(fieldName)); } } catch (Exception e) { Debug.LogWarning("Failed to get property " + fieldName + ". Check device API level. " + e.Message); return(string.Empty); } }
static string GetStringProperty(string propertyName) { if (AGUtils.IsNotAndroidCheck()) { return(string.Empty); } try { using (var env = new AndroidJavaClass(C.AndroidOsEnvironment)) { return(env.GetStaticStr(propertyName)); } } catch (Exception e) { Debug.LogWarning("Could not get the property: " + propertyName + ". Check the device API level if the property is present, reason: " + e.Message); return(string.Empty); } }