Android Advertising ID

Android Advertising ID

Advertising ID is to track user for advertisement use.
This is Unique ID per device, but the user can change by their operation “Google Setting”
Basially, the use

How to get

We need Google Service SDK Library
If you use Android Studio, it’s so simple.
“File” -> “Project Structure” -> “Modules” -> “Dependencies”

googleplayservice

playservice2

This is sample code to get Google Advertising ID

Thread adIdThread = new Thread(new Runnable() {
  @Override
  public void run() {
    AdvertisingIdClient.Info adInfo = null;
    try {
      adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
      final String id = adInfo.getId();
      final boolean isLAT = adInfo.isLimitAdTrackingEnabled();

      if (!isLAT) {
        // Do something
      }
    } catch (Exception e) {
 }
}
});
adIdThread.start();

In android, event the user disabled advertising feature, the developer can get Advertising ID.
The use depends on developers

The code is asynchronous.