< disclaimer: Welcome reprint, but please keep the original source of the article >
This article excerpt from:Https://blog.safaribooksonline.com/2014/01/16/advertising-id-android-kitkat/?utm_source=tuicool
Beginning in August, Google would replace the Android ID with the new Google advertising ID.
Because advertising ID is part of the Google Play Services platform, you must first get the Google Play services SDK and S ET up your project. Note that Google provides good documentation on setting up the SDK which includes the following steps:
- Copy the Google SDK Library and import it into your project.
- Update your app Manifest file.
- Create a Proguard exception to prevent Proguard from stripping away required classes.
- Ensure Devices has the Google Play services APK.
See Install the Google Play Services SDK for more information.
Once Setup, you'll use com.google.android.gms.ads.identifier
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 a AdvertisingIdClient.Info
object by calling the method getAdvertisingIdInfo()
. Note that this must is done with its own thread and is on the main thread or you'll get a IllegalStateException
. The following code snippet shows an example of what to get the advertising ID:
1 Importcom.google.android.gms.ads.identifier.AdvertisingIdClient;2 ImportCom.google.android.gms.ads.identifier.AdvertisingIdClient.Info;3 :4 :5 6Info Adinfo =NULL;7 8 Try {9Adinfo =Advertisingidclient.getadvertisingidinfo (mcontext);Ten}Catch(IOException e) { One ... A}Catch(googleplayservicesavailabilityexception e) { - ... -}Catch(googleplayservicesnotavailableexception e) { the ... - } - -String AdId =Adinfo.getid (); + -:
Once you get the advertising ID of your can use it instead of using the non-anonymous Android device ID.
Summary
Developers has 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.
< disclaimer: Welcome reprint, but please keep the original source of the article >