Posted on by & filed under Content - Highlights and Reviews, Programming & Development.

code A guest post by C. Enrique Ortiz, an industry-recognized Mobilist, Author and Blogger. You can reach Enrique at He is co-founder of Kloc, which helps developers to effortlessly create visually awesome and interactive Developer Portfolios. Create your own Developer Portfolio by visiting and share with others.

In a previous post covering Android 4.4 or KitKat, I discussed some of the great new features for Android developers. I then went on to cover how to enable voice communications in Android. Now, in this post we’ll explore Android’s new anonymous advertising identifier introduced with Android 4.4 Kitkat and why as a developer you should take advantage of it in your Android apps.


The ability to identify users is important for advertising, analytics and other purposes. Android developers typically rely on the Android Device ID or Telephony IDs such as the International Mobile Equipment Identity (IMEI) to uniquely identify users, but these approaches also introduce privacy concerns. Android 4.4 Kitkat introduces a new anonymous identifier for advertising purposes. Referred to as Advertising ID, it provides a user-resettable identifier that helps protect the user’s personal identity. Google defines Advertising ID as follows:

“The advertising ID is a user-specific, unique, resettable ID for advertising, provided by Google Play services. It gives users better controls and provides developers with a simple, standard system to continue to monetize your apps. It is an anonymous identifier for advertising purposes and enables users to reset their identifier or opt out of interest-based ads within Google Play apps. The advertising ID is accessible through a straightforward API that you can implement in your apps.”

Advertising ID is supported in Google Play services 4.0+, and follows the format of UUID, for example: “96bd03b6-defc-4203-83d3-dc1c730801f7“.

Using the Advertising ID

Because Advertising ID is part of the Google Play services platform, you must first get the Google Play services SDK and set up your project. Note that Google provides good documentation on setting up the SDK which includes the following steps:

  1. Copy the Google SDK library and import it into your project.
  2. Update your app Manifest file.
  3. Create a ProGuard exception to prevent ProGuard from stripping away required classes.
  4. Ensure Devices Have the Google Play services APK.

See Install the Google Play Services SDK for more information.

Once setup, you will use the classes in package, shown here:

Class Description
AdvertisingIdClient A helper library for retrieval of advertising ID and related information.
AdvertisingIdClient.Info Includes both the advertising ID as well as the limit ad tracking setting.

To get the Advertising ID, you must first get an AdvertisingIdClient.Info object by calling the method getAdvertisingIdInfo(). Note that this must be done on its own thread and not on the main thread or you will get an IllegalStateException. The following code snippet shows an example of how to get the Advertising ID:

Once you get the advertising ID you can use it instead of using the non-anonymous Android device ID.

Resetting the Advertising ID

The advertising ID can only be reset by the user via the Google Settings application (the APIs do not include a reset method). The following illustrates the Google Settings screen that shows the advertising ID and how to reset it.



Developers have a number of options to generate unique user identifiers. These include Telephony identifiers such as IMEI or the Android Device ID. Starting with Android 4.4, developers can use the Advertising ID that provides a user-specific, unique, and resettable ID for advertising, as provided by Google Play services.

For more details about developing Android apps, see the resources below from Safari Books Online.

Not a subscriber? Sign up for a free trial.

Safari Books Online has the content you need

Expert Android gives you advanced techniques for customizing views, controls, and layouts. You’ll learn to develop apps in record time using JSON, Advanced Form Processing, and the BaaS (Backend As A Service) platform Parse. The book also includes extensive coverage on OpenGL, Search, and Telephony. With these advanced and time saving technologies you’ll be able to release compelling mobile applications in Google Play and the Amazon Appstore at a rapid pace.
Embedded Android is for Developers wanting to create embedded systems based on Android and for those wanting to port Android to new hardware, or creating a custom development environment. Hackers and modders will also find this an indispensable guide to how Android works.
Android Cookbook helps you find solutions for working with Android user interfaces, multitouch gestures, location awareness, web services, and device features such as the phone, camera, and accelerometer. You also get useful steps on packaging your app for the Android Market.

Tags: Advertising ID, Android 4.4, Android Device ID, Google Play Services, IMEI, KitKat, privacy, security,

Comments are closed.