0

I need to get the AndroidID using ADB and inside the unity application check if it's the same device using the AndroidID.

With this command, using ADB I have the AndroidID:

adb shell settings get secure android_id
>> a9822db857e4****

And inside the unity application, I'm using this code:

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.CallStatic<string>("getString", objResolver, "android_id");
>> android_id = 98ff3a034b16****

You may notice that the IDs are different. Does anyone have a solution for this? How can I get that same identifier using ADB and in unity ?

eb1t
  • 57
  • 1
  • 4

1 Answers1

0

If your device runs Android version > Android 8.0 (API level 26), the ANDROID_ID string is unique to each app (more precisely, to each app-signing key - so more like unique to all your apps you signed with the same key). You can check out all the changes related to ANDROID_ID here.

If you are running Android version < 8.0, you might have multiple users and they will have separate ids - maybe you are getting root users' id via ADB and the whatever-user-launched-your-app id from code? (See here).

defaultUsernameN
  • 365
  • 5
  • 14