Android获取谷歌AdvertisingID

<声明:欢迎转载,但请保留文章原始出处>

本文摘抄自:https://blog.safaribooksonline.com/2014/01/16/advertising-id-android-kitkat/?utm_source=tuicool

 

Beginning in August, Google will 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 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 com.google.android.gms.ads.identifier, shown here:

 

ClassDescription
AdvertisingIdClientA helper library for retrieval of advertising ID and related information.
AdvertisingIdClient.InfoIncludes 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:

 1 import com.google.android.gms.ads.identifier.AdvertisingIdClient;
 2 import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
 3 :
 4 :
 5 
 6 Info adInfo = null;
 7 
 8 try {
 9      adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
10 } catch (IOException e) {
11      ...
12 } catch (GooglePlayServicesAvailabilityException e) {
13      ...
14 } catch (GooglePlayServicesNotAvailableException e) {
15      ...
16 }
17 
18 String AdId = adInfo.getId();
19 
20 :

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

Summary

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.

 

<声明:欢迎转载,但请保留文章原始出处>

 

转载于:https://www.cnblogs.com/doris-coding-time/p/3880452.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值