public static void GetUniqueIdentifier(UniqueIdentifierDelegate callback) { #if UNITY_IPHONE && !UNITY_EDITOR GetiOSIdentifier(callback); #elif UNITY_ANDROID && !UNITY_EDITOR GetAndroidIdentifier(callback); #else var password = SystemInfo.deviceUniqueIdentifier; callback(password); #endif }
private static void GetAndroidIdentifier(UniqueIdentifierDelegate callback) { string password; try { using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (var currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) { using (var wifiManager = currentActivity.Call <AndroidJavaObject>("getSystemService", "wifi")) { using (var wInfo = wifiManager.Call <AndroidJavaObject>("getConnectionInfo")) { password = wInfo.Call <string>("getMacAddress"); } } } } } catch (AndroidJavaException) { Log.Warning(nameof(DeviceUniqueIdentifier), "No android.permission.ACCESS_WIFI_STATE."); password = ""; } if (!string.IsNullOrEmpty(password) && !password.Equals(UnsupportMacAddress)) { password = ToMd5(password); callback(password); } else { if (!Application.RequestAdvertisingIdentifierAsync( (advertisingId, trackingEnabled, error) => { if (advertisingId.Equals(string.Empty)) { password = SystemInfo.deviceUniqueIdentifier; callback(password); } else { callback(advertisingId); } } )) { password = SystemInfo.deviceUniqueIdentifier; callback(password); } } }
private static void GetiOSIdentifier(UniqueIdentifierDelegate callback) { var password = _Get_Device_id(); callback(password); }