9

It seems that the way to access the advertising ID that worked in Unity3d 2019.4, RequestAdvertisingIdentifierAsync is deprecated for android in the 2020.1 release.

How can I access the advertising id in that version?

eran
  • 14,496
  • 34
  • 98
  • 144
  • May I ask how do you know it's deprecated? – Konstantine Rybnikov Sep 15 '20 at 17:10
  • 1
    Did you manage it? Please post a solution. – Sam Tyurenkov Jan 20 '21 at 00:58
  • Patch notes also confirm https://unity3d.com/unity/beta/2020.1.0b14 "Android: Changed: Application.RequestAdvertisingIdentifierAsync does nothing now" – Patrick Fay Mar 12 '21 at 02:09
  • If all else fails you may be able to request it directly from the Google API. If so, the information in the question and answer on this page might be of use potentially: https://stackoverflow.com/questions/34582610/unity-android-get-google-play-advertising-id – Sven Viking Mar 25 '22 at 23:20

1 Answers1

0

Manually call into Java:

    public static string GetAndroidAdvertiserId()
    {
        string advertisingID = "";
        try
        {
            AndroidJavaClass up = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject> ("currentActivity");
            AndroidJavaClass client = new AndroidJavaClass ("com.google.android.gms.ads.identifier.AdvertisingIdClient");
            AndroidJavaObject adInfo = client.CallStatic<AndroidJavaObject> ("getAdvertisingIdInfo", currentActivity);
    
            advertisingID = adInfo.Call<string> ("getId").ToString();  
        }
        catch (Exception)
        {
        }
        return advertisingID;
    }
Luc Bloom
  • 1,120
  • 12
  • 18