I want to get users Advertising ID programmatically.I used the below code from the developer site.But its not working
Info adInfo = null;
Make sure you have added play identity services, then you can get advertising id by running a thread like this:
Thread thread = new Thread() {
@Override
public void run() {
try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
String advertisingId = adInfo != null ? adInfo.getId() : null;
} catch (IOException | GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException exception) {
exception.printStackTrace();
}
}
};
// call thread start for background process
thread.start();