
com.segment.analytics.GetAdvertisingIdTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
The hassle-free way to add analytics to your Android app.
package com.segment.analytics;
import android.content.Context;
import android.os.AsyncTask;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
class GetAdvertisingIdTask extends AsyncTask {
final AnalyticsContext analyticsContext;
GetAdvertisingIdTask(AnalyticsContext analyticsContext) {
this.analyticsContext = analyticsContext;
}
@Override protected AdvertisingIdClient.Info doInBackground(Context... contexts) {
try {
return AdvertisingIdClient.getAdvertisingIdInfo(contexts[0]);
} catch (Exception ignored) {
return null;
}
}
@Override protected void onPostExecute(AdvertisingIdClient.Info info) {
super.onPostExecute(info);
if (info != null) {
analyticsContext.putAdvertisingInfo(info.getId(), info.isLimitAdTrackingEnabled());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy