Last active
November 22, 2023 13:31
-
-
Save TarasOsiris/9270285 to your computer and use it in GitHub Desktop.
Unity3d method to retrieve device ANDROID_ID constant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public static class AndroidIdRetriever | |
{ | |
public static string Retrieve() | |
{ | |
AndroidJavaClass clsUnity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | |
AndroidJavaObject objActivity = clsUnity.GetStatic<AndroidJavaObject>("currentActivity"); | |
AndroidJavaObject objResolver = objActivity.Call<AndroidJavaObject>("getContentResolver"); | |
AndroidJavaClass clsSecure = new AndroidJavaClass("android.provider.Settings$Secure"); | |
string ANDROID_ID = clsSecure.GetStatic<string>("ANDROID_ID"); | |
string androidId = clsSecure.CallStatic<string>("getString", objResolver, ANDROID_ID); | |
return androidId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment