In Unity 2020+ Application.RequestAdvertisingIdentifierAsync returns nothing. Forum thread #1 thread #2
This package uses AdvertisingIdClient
MiniIT.Utils.AdvertisingIdFetcher.RequestAdvertisingId((advertisingId, trackingEnabled, error) =>
{
Debug.Log("advertisingId = " + advertisingId);
});
Optionally you may specify a timeout in milliseconds for this operation by passing the second parameter. Default timeout is 1000 ms. If the operation lasts longer, it is forced to stop and the callback
will be called with an empty string as a parameter.
If the timeout value is less or equal to zero, no timeout is applied.
To add AdvertisingIdFetcher to your project follow these instructions using this Git URL:
https://github.com/Mini-IT/AdvertisingIdentifierFetcher.git
External Dependency Manager for Unity will help you to resolve dependencies.
Or alternatively you can do it manually following these steps:
- Create custom main gradle template file. Project Settings -> Player -> Android Tab -> Publish Settings -> Custom Main Gradle Template Tick;
- Open Assets/Plugins/Android/mainTemplate.gradle with any text editor and add the following line into
dependencies
section:
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
Advertising Identifier Fetcher uses conditional compilation. On any other platform but Android Application.RequestAdvertisingIdentifierAsync will be used.