Android获取Advertising ID

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

本文摘抄自: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:

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:

 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.

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

Android获取Advertising ID

时间: 2024-08-08 06:59:54

Android获取Advertising ID的相关文章

Android获取系统ID(com.android.internal.R)

R.id.icon 怎么获取,这个东西其实在 com.android.internal.R 这个里面,但是这个类我们访问不到怎么办? 反射呗, Java 的反射可谓是万能啊,啥都可以拿到只要他在. [java] view plaincopy Class<?> clazz = Class.forName("com.android.internal.R$id"); Field field = clazz.getField("icon"); field.set

Android_使用getIdentifier()获取资源Id

Android 获取资源ID的另外一种方法,常规获取ID是在特定的文件夹下面的资源,如果在比较特殊的文件夹下面,就需要其他方法获取ID 了: 使用getIdentifier()方法可以方便的获各应用包下的指定资源ID.主要有两种方法:(1)方式一 Resources resources = context.getResources(); int indentify = resources.getIdentifier(org.loveandroid.androidtest:drawable/ico

Android Advertising ID 简介以及快速集成和使用

AdVertising ID (广告ID) 广告id是用户特殊的,独特的,可重置的广告id,由Google Play Service 提供,它为用户更好的控制,为开发人员提供简单.标准的系统继续使用你的应用程序,它用于广告目的的匿名标示符和或者重置起标示符或者退出以利益为基础的Google Play的医用程序. 广告 ID 可以通过简单的API在你的应用程序中实现. 重点开发功能 标准简单--广告标识是一个标准的一部分,为广告和简单的系统进行分析. 让用户控制--用户可以在任何时候设置他们的ID

Android:资源 id 及资源 id 的动态获取

我们平时获取资源是通过 findViewById 方法进行的,比如我们常在onCreate方法中使用这样的语句: btnChecked=(ImageView)findViewById(R.id.imgCheck); findViewById是我们获取layout中各种View 对象比如按钮.标签.ListView和ImageView的便利方法.顾名思义,它需要一个int参数:资源id. 资源id非常有用.Android回自动为每个位于res目录下的资源分配id,包括各种图片文件.xml文中的"@

android robotium获取相同id的的控件

android robotium获取相同id的的控件:http://blog.csdn.net/busjb/article/details/16808551 robotium中同一id的怎么确定点击哪一个:http://zhidao.baidu.com/link?url=QMTQ86nIqfGS8l1xkiytlIguSnG3UZC-C77q3qoGTfOc4AlzJNqVobbfYtfElhFEaEXfnmfla3spwC9snUfAeZGJykAlWLIDHfvTjuimXPG androi

Android使用getIdentifier()方法根据资源名来获取资源id

有时候我们想动态的根据一个资源名获得到对应的资源id,就可以使用getResources().getIdentifier()方法来获取该id.然后再使用该id进行相关的操作. 1.Demo示例 下面用一个小Demo来讲解如何使用getResources().getIdentifier()方法来获取该id. 例如,新建一个Android项目,项目结构部分截图如下所示: MainActivity代码如下: package com.oyp.demo; import android.os.Bundle;

android应用循环获取资源Id之引导页

目前市面上几乎所有的APP应用在第一次使用时都会有个引导页面,要么用引导用户操作,要么介绍产品优势,要么用来打广告等.引导页面一般是由3-6张图形界面组成,好的引导页面也不失为该app的亮丽风景!今天我也来说说引导页面的设计(当然有N种方法),我只是把我们项目中用到的方法代码贴出来,方便自己做个笔记. 我们实现的原理很简单,就是用一个ViewPager全屏展示一些图片,主要代码如下: 主页面布局: <?xml version="1.0" encoding="utf-8&

android 获取相册列表的实现(三)

该项目实现的功能如下: 获取手机相册,点击每个相册之后进入该相册的图片列表界面,在图片列表界面可以实现图片多选,然后进入所选择的图片界面,在该界面内可以实现所选图片的上传等功能. 该项目最大特色: 1.获取相册列表,目前网络上面介绍获取相册的项目很少,本文专门讲述相册的获取. 2.使用Android-Universal-Image-Loader集成框架-第三方jar包加载本地图片,熟悉这个jar的开发者肯定不陌生,该jar包十分强大,除了可以获取网络图片,本地图片也是可以的.同时,通过引用第三方

Android获取LayoutInflater对象的方法总结

在写Android程序时,有时候会编写自定义的View,使用Inflater对象来将布局文件解析成一个View.本文主要目的是总结获取LayoutInflater对象的方法. 1.若能获取context对象,可以有以下几种方法: LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View child = inflater.inflate(R.la