AdvertisingIdClient
Stay organized with collections
Save and categorize content based on your preferences.
Helper library for retrieval of advertising ID and related information such as the limit
ad tracking setting.
It is intended that the advertising ID completely replace existing usage of other
identifiers for ads purposes (such as use of ANDROID_ID
in Settings.Secure
)
when Google Play Services is available. Cases where Google Play Services is unavailable are
indicated by a
GooglePlayServicesNotAvailableException
being thrown by
getAdvertisingIdInfo().
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Methods
Retrieves the user's advertising ID and limit ad tracking preference.
This method cannot be called in the main thread as it may block leading to ANRs. An
IllegalStateException
will be thrown if this is called on the main
thread.
Returns
- AdvertisingIdClient.Info with user's advertising ID and limit ad tracking
preference.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eAdvertisingIdClient\u003c/code\u003e helps retrieve advertising ID and limit ad tracking setting, intended to replace other identifiers like \u003ccode\u003eANDROID_ID\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetAdvertisingIdInfo()\u003c/code\u003e retrieves the user's advertising ID and limit ad tracking preference, but should not be called on the main thread.\u003c/p\u003e\n"],["\u003cp\u003eIf Google Play Services is unavailable, a \u003ccode\u003eGooglePlayServicesNotAvailableException\u003c/code\u003e will be thrown.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAdvertisingIdClient.Info\u003c/code\u003e class contains both the advertising ID and the limit ad tracking setting.\u003c/p\u003e\n"]]],["The `AdvertisingIdClient` class helps retrieve a user's advertising ID and their limit ad tracking setting, meant to replace other identifiers like `ANDROID_ID`. The `getAdvertisingIdInfo(Context context)` method is key, returning an `AdvertisingIdClient.Info` object containing this data. This method must not be called on the main thread and throws exceptions like `IOException`, `IllegalStateException`, or `GooglePlayServicesNotAvailableException` for connection or availability issues with Google Play Services.\n"],null,["# AdvertisingIdClient\n\npublic class **AdvertisingIdClient** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nHelper library for retrieval of advertising ID and related information such as the limit\nad tracking setting.\n\nIt is intended that the advertising ID completely replace existing usage of other\nidentifiers for ads purposes (such as use of `ANDROID_ID` in [Settings.Secure](//developer.android.com/reference/android/provider/Settings.Secure.html))\nwhen Google Play Services is available. Cases where Google Play Services is unavailable are\nindicated by a [GooglePlayServicesNotAvailableException](/android/reference/com/google/android/gms/common/GooglePlayServicesNotAvailableException) being thrown by\ngetAdvertisingIdInfo(). \n\n### Nested Class Summary\n\n|-------|---|---|----------------------------------------------------------------------------|\n| class | [AdvertisingIdClient.Info](/android/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info) || Includes both the advertising ID as well as the limit ad tracking setting. |\n\n### Public Method Summary\n\n|----------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [AdvertisingIdClient.Info](/android/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info) | [getAdvertisingIdInfo](/android/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient#getAdvertisingIdInfo(android.content.Context))([Context](//developer.android.com/reference/android/content/Context.html) context) Retrieves the user's advertising ID and limit ad tracking preference. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public static [AdvertisingIdClient.Info](/android/reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info)\n**getAdvertisingIdInfo** ([Context](//developer.android.com/reference/android/content/Context.html) context)\n\nRetrieves the user's advertising ID and limit ad tracking preference.\n\nThis method cannot be called in the main thread as it may block leading to ANRs. An\n`IllegalStateException` will be thrown if this is called on the main\nthread. \n\n##### Parameters\n\n| context | Current [Context](//developer.android.com/reference/android/content/Context.html) (such as the current [Activity](//developer.android.com/reference/android/app/Activity.html)). |\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- AdvertisingIdClient.Info with user's advertising ID and limit ad tracking preference. \n\n##### Throws\n\n| [IOException](//developer.android.com/reference/java/io/IOException.html) | signaling connection to Google Play Services failed. |\n| [IllegalStateException](//developer.android.com/reference/java/lang/IllegalStateException.html) | indicating this method was called on the main thread. |\n| [GooglePlayServicesNotAvailableException](/android/reference/com/google/android/gms/common/GooglePlayServicesNotAvailableException) | indicating that Google Play is not installed on this device. |\n| [GooglePlayServicesRepairableException](/android/reference/com/google/android/gms/common/GooglePlayServicesRepairableException) | indicating that there was a recoverable error connecting to Google Play Services. |\n|-------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|"]]