1f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertypage.title=Advertising ID 233baa5ad7d8cdcc89ce4fbc3bc8cd537d5f5d639Joe Fernandezpage.tags=Ads,Advertising ID,ID 3f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyheader.hide=1 4f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 5f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty@jd:body 6f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 7f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<div class="landing-banner"> 8f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 9f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<div class="col-8"> 10f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 11f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h1 itemprop="name" style="margin-bottom:0;">Advertising ID</h1> 1228167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty <p itemprop="description">The advertising ID is a user-specific, unique, 1328167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty resettable ID for advertising, provided by Google Play services. It gives 1428167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty users better controls and provides developers with a simple, standard system 1528167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty to continue to monetize your apps. It is an anonymous identifier for advertising 1628167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty purposes and enables users to reset their identifier or opt out of interest-based 1728167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty ads within Google Play apps. </p> 18f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 19f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p>The advertising ID is accessible through a straightforward API that you can implement in your apps. For details, 20f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertytake a look at the 21f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<a href="#get_started">overview</a> and the <a 22f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyhref="{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">advertising ID API reference</a>. 23f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 24f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</div> 25f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</div> 26f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 27f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<div class="landing-docs"> 28f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <div class="col-6 normal-links"> 29f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h3 style="clear:left">Key Developer Features</h3> 30f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 31f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h4>Standard, simple ID</h4> 32f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <p>The advertising ID is a part of a standard, simple system for serving ads and performing analytics.</p> 33f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 34f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h4>Giving users control</h4> 35f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <p>Users can reset their advertising ID or opt out of interest-based ads at any time, right from the Google Settings app. 36f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Their preferences apply across all ad companies that use the advertising ID.</p> 37f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 38f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty </div> 39f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 40f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <div class="col-6 normal-links"> 41f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h3 style="clear:left">Getting Started</h3> 42f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h4>1. Get the Google Play services SDK</h4> 43f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <p>The advertising ID APIs are part of the Google Play services platform.</p> 44f12b3fd617e507226c676a631b4c8bf1dd9748e1Scott Main <p>To get started, <a href="{@docRoot}google/play-services/setup.html">set up 45f12b3fd617e507226c676a631b4c8bf1dd9748e1Scott Main the Google Play services SDK</a>. </p> 46f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 47f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <h4>2. Read the docs and example code</h4> 48f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <p>Once you've installed the Google Play services package, review the <a href="#get_started">overview</a> 49f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty below, as well as the <a href="#example">example</a>.</p> 50f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <p> 51f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty For detailed documentation, take a look at the <a href= 52f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html"> 53f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty advertising ID API reference documentation</a>. 54f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty </p> 55f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty </div> 56f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</div> 57f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 58f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty<p class="caution" style= 59f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty"background-color:#fffdeb;width:100%;margin-bottom:1em;padding:.5em;"> 60f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty As a reminder, please note that starting <strong>1 August 2014</strong>, new 61f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty apps and app updates distributed through Google Play must use the advertising 62f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty ID in lieu of any other persistent identifiers for any advertising purposes, 63f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty on devices that support the advertising ID.<br> 64f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty <br> 65f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty To learn how to check your app's compliance through the Developer Console, or 66f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty for details on the associated developer policy changes, please see the 67f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty <a href= 68f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty "https://support.google.com/googleplay/android-developer/answer/6048248">Advertising 69f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty ID topic</a> in the Google Play developer help center. 70f365928406ef0a80d3aecc2d025642f9efb80a05Dirk Dougherty</p> 71f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 72f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<h2 id="get_started">Using the Advertising ID</h2> 73f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 74f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 75f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty The <strong>advertising ID</strong> is a unique but 76f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty user-resettable string identifier that lets ad networks and other apps anonymously 77f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty identify a user. The user's advertising ID is made available to apps through APIs 78f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty provided in Google Play services. 79f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 80f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 81f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Users can reset their advertising ID at any time, right from the Ads section of the 82f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Google Settings app on their devices. From the same app, users can also 83f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty opt-out of targeted advertising based on the advertising ID by setting the appropriate 84f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <strong style="white-space:nowrap">ad tracking preference</strong>. When the 85f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty user opts-out of targeted ads, this ad tracking preference is made available 86f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty to apps through a Google Play services API. 87f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 88f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 89f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Apps making use of the advertising ID <strong>must check for and respect</strong> the 90f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty user's ad tracking preference. Also please note that any use of the advertising ID 9128167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty must abide by the terms of the <a class="external-link" 9228167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty href="http://play.google.com/about/developer-content-policy.html#ADID">Google Play 9328167899617b59874aeeb0f6cd822ca2f6cc9e55Dirk Dougherty Developer Content Policies</a>. 94f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 95f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 96f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<h3 id="format">Format of the Advertising ID</h3> 97f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 98f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 99f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Google Play services APIs expose the user's advertising ID as a string format of UUID, 100f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty with values similar to this: 101f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 102f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p style="margin-left:1.5em;"><code>“38400000-8cf0-11bd-b23e-10b96e40000d”</code></p> 103f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 104f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<h3 id="requirements">Requirements</h3> 105f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 106f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<ul> 107f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <li>The advertising ID APIs are supported in Google Play services 4.0+</li> 108f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <li>Support for the advertising ID on specific devices is based on their installed versions 109f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty of Google Play services</li> 110f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</ul> 111f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 112f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<h3 id="obtaining">Obtaining the user's advertising ID and ad tracking preference</h3> 113f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 114f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 115f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty If you want to use the advertising ID in your app, you must first install the Google 116f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Play services SDK. As noted in the requirements above, you should install the 117f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty SDK for Google Play services 4.0 or higher if you will develop using the advertising ID 118f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty APIs. For information about how to get started, see <a href= 119f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}google/play-services/setup.html">Set Up Google Play services</a>. 120f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 121f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 122f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty The advertising ID APIs are available in the <a href= 123f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html"> 124f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <code>com.google.android.gms.ads.identifier</code></a> package in the Google 125f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Play Services library. To obtain the user's advertising ID and tracking preference, 126f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty call the method 127f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <a href= 128f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html#getAdvertisingIdInfo(android.content.Context)"> 129f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <code>getAdvertisingIdInfo()</code></a>, which returns an <a href= 130f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html"> 131f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <code>AdvertisingIdClient.Info</code></a> encapsulating the user's current Advertising ID 132f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty and tracking preference. 133f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 134f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 135f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p class="note"> 136f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <strong>Note:</strong> The <code>getAdvertisingIdInfo()</code> method is a 137f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty blocking call, so you must not call it on the main (UI) thread. If called on 138f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty the main thread, the method throws <code>IllegalStateException</code>. 139f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 140f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 141f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 142f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Once you've retrieved the <code>AdvertisingIdClient.Info</code> object, you 143f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty can use it's <a href= 144f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html#getId()"> 145f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <code>getId()</code></a> and <a href= 146f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html#isLimitAdTrackingEnabled()"> 147f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty <code>isLimitAdTrackingEnabled()</code></a> methods to access the advertising ID and 148f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty ad tracking preference. 149f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 150f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 151f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<table> 152f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<tr> 153f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<th>Method</th> 154f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<th>Description</th> 155f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</tr> 156f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<tr> 157f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<td><code>public String getId()</code></td> 158f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<td style="white-space:nowrap;">Retrieves the advertising ID.</td> 159f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</tr> 160f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<tr> 161f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<td style="white-space:nowrap;"><code>public boolean isLimitAdTrackingEnabled()</code></td> 162f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<td>Retrieves whether the user has limit ad tracking enabled or not.</td> 163f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</tr> 164f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</table> 165f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 166f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 167f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty The advertising ID APIs do not include a "reset" method. Only users can initiate a 168f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty reset of their own advertising IDs, through the Google Settings application. 169f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 170f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 171f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty For more information about the advertising ID APIs, see the <a href= 172f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html"> 173f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty reference documentation</a>. 174f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 175f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 176f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<h3 id="example">Example implementation</h3> 177f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 178f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<p> 179f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Here's a basic illustration of how you can retrieve the user's advertising ID and ad 180f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty tracking preference in your app: 181f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty</p> 182f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 183f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty<pre> 184f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyimport com.google.android.gms.ads.identifier.AdvertisingIdClient; 185f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyimport com.google.android.gms.ads.identifier.AdvertisingIdClient.Info; 186f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyimport com.google.android.gms.common.GooglePlayServicesAvailabilityException; 187f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyimport com.google.android.gms.common.GooglePlayServicesNotAvailableException; 188f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertyimport java.io.IOException; 189f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty... 190f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 191f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty// Do not call this function from the main thread. Otherwise, 192f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty// an IllegalStateException will be thrown. 193f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Doughertypublic void getIdThread() { 194f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 195f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty Info adInfo = null; 196f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty try { 197f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext); 198f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 199f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty } catch (IOException e) { 200f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty // Unrecoverable error connecting to Google Play services (e.g., 201f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty // the old version of the service doesn't support getting AdvertisingId). 202f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 203f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty } catch (GooglePlayServicesAvailabilityException e) { 204f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty // Encountered a recoverable error connecting to Google Play services. 205f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty 206f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty } catch (GooglePlayServicesNotAvailableException e) { 207f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty // Google Play services is not available entirely. 208f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty } 209f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty final String id = adInfo.getId(); 210f04c9b8e85d0b32165de8dd20cac74d0840c4569Dirk Dougherty final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); 21133baa5ad7d8cdcc89ce4fbc3bc8cd537d5f5d639Joe Fernandez}</pre> 212