知識(shí)
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷(xiāo)的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷(xiāo)工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!
GoogleAdvertisingID簡(jiǎn)介以及快速集成和使用
發(fā)表時(shí)間:2020-10-19
發(fā)布人:葵宇科技
瀏覽次數(shù):243
AdVertising ID (告白ID)
告白id是用戶特別的,獨(dú)特的,可重置的告白id,由Google Play Service 供給,它為用戶更好的┞菲握,為開(kāi)辟人員供給簡(jiǎn)單、標(biāo)準(zhǔn)的體系持續(xù)應(yīng)用你的應(yīng)用法度榜樣,它用于告白目標(biāo)的匿名標(biāo)示符和或者重置起標(biāo)示符或者退出以好處為基本的Google Play的醫(yī)用法度榜樣。
告白 ID 可以經(jīng)由過(guò)程簡(jiǎn)單的API在你的應(yīng)用法度榜樣中實(shí)現(xiàn)。
重點(diǎn)開(kāi)辟功能
標(biāo)準(zhǔn)和R單——告白標(biāo)識(shí)是一個(gè)標(biāo)準(zhǔn)的一部分,為告白和R單的體系進(jìn)行分析。
讓用戶控制——用戶可以在任何時(shí)刻設(shè)置他們的ID或者退出那些以好處為基本的告白大年夜谷歌的應(yīng)用法度榜樣,他們的偏罕善于告白公司的告白ID。
開(kāi)端
獲取Google Play Service SDK——大年夜下載好的Android SDK 的 Extras 目次下找 library 下面的google-play-service.jar
瀏覽文檔和例子——文檔例子
注釋
作為提示,請(qǐng)留意,大年夜2014-08-01,新的應(yīng)用法度榜樣和應(yīng)用法度榜樣的更新經(jīng)由過(guò)程谷歌晃蕩必須在任何告白目標(biāo)的任何其他持久標(biāo)識(shí)符代替應(yīng)用告白ID設(shè)備上支撐的告白
若何檢查您的應(yīng)用法度榜樣的合規(guī)性經(jīng)由過(guò)程開(kāi)辟控制臺(tái),或在相干的開(kāi)辟政策變更的細(xì)節(jié),請(qǐng)看在谷歌游戲開(kāi)辟者贊助中間告白ID的參考
應(yīng)用告白ID
告白標(biāo)識(shí)是一個(gè)獨(dú)特的但用戶復(fù)位字符串標(biāo)識(shí)符,讓收集告白和其他應(yīng)用法度榜樣的匿名標(biāo)識(shí)一個(gè)用戶。用戶的告白ID是經(jīng)由過(guò)程API供給的辦事供給給應(yīng)用法度榜樣的在Google Play Service中。
用戶可以在任何時(shí)刻設(shè)置他們的告白ID,大年夜谷歌設(shè)置應(yīng)用法度榜樣在設(shè)畢喔贍告白部分的權(quán)力。大年夜雷同的應(yīng)用法度榜樣,用戶還可以選擇有針對(duì)性的告白的告白ID的基本上,來(lái)設(shè)置合適的告白跟蹤偏好。當(dāng)用戶選擇了有針對(duì)性的告白,這個(gè)告白跟蹤偏好是供給給應(yīng)用法度榜樣經(jīng)由過(guò)程谷歌播放辦事API。
應(yīng)用法度榜樣應(yīng)用告白必須尊檢查并尊敬用戶的習(xí)慣和偏好跟蹤,還請(qǐng)留意,任何應(yīng)用告白id的應(yīng)用法度榜樣都必須尊敬Google的開(kāi)辟內(nèi)容政策條目。
ID 格式
Google Play Service 的API 裸露和用戶的 ID 為 UUID 的字符串格式。
須要
告白 ID API支撐Google Play Service 4.0+ 的設(shè)備
對(duì)具體設(shè)備的支撐是基于設(shè)備安裝的Google Paly Service 的版本
用戶的告白ID和告白跟蹤優(yōu)先獲得
如不雅你應(yīng)用法度榜樣想要應(yīng)用告白ID,你的設(shè)備就必須安裝Google Play Service
告白ID的API可在com.google.android.gms.ads.identifier包在Google Play Service的的庫(kù)中。獲得用戶的告白ID和跟蹤偏好,調(diào)用辦法getadvertisingidinfo(),它返回一個(gè)advertisingidclient信息封裝。用戶當(dāng)前的告白ID和跟蹤偏好。
getadvertisingidinfo()辦法的壅塞調(diào)用,所以你不克不及說(shuō)它在主線程(UI線程)。如不雅在主線程,該辦法拋出illegalstateexception異常。
一旦你取回advertisingidclient對(duì)象,您可以應(yīng)用它的getid()和islimitadtrackingenabled()辦法拜訪的告白ID和告白跟蹤偏好。
Method Description
public String getId()
Retrieves the advertising ID.
public boolean isLimitAdTrackingEnabled()
Retrieves whether the user has limit ad tracking enabled or not.
告白ID API不包含“復(fù)位”的辦法。只有效戶可以啟動(dòng)復(fù)位本身的告白ID,在Google
Play Service設(shè)置中。
例子一:
獲取ID要放在子線程中,這種方法是要把google-play-service.jar放在項(xiàng)目標(biāo)lib下,全部jar大年夜概有3M多,還有一種不須要集成jar的方法見(jiàn)例子二。
import com.google.android.gms.ads.identifier.AdvertisingIdClient; import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info; import com.google.android.gms.common.GooglePlayServicesAvailabilityException; import com.google.android.gms.common.GooglePlayServicesNotAvailableException; import java.io.IOException; ... // Do not call this function from the main thread. Otherwise, // an IllegalStateException will be thrown. public void getIdThread() { Info adInfo = null; try { adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesAvailabilityException e) { // Encountered a recoverable error connecting to Google Play services. } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } final String id = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); }
例子二:
不須要集成google-play-service.jar怎么獲取呢?
這種方法就請(qǐng)求手機(jī)本身安裝了Google Play Service,這里采取綁定Service和夸過(guò)程通信的方法獲取告白ID。
創(chuàng)建一個(gè)類(lèi) AdvertisingIdClient.java
public class AdvertisingIdClient { public static final class AdInfo { private final String advertisingId; private final boolean limitAdTrackingEnabled; AdInfo(String advertisingId, boolean limitAdTrackingEnabled) { this.advertisingId = advertisingId; this.limitAdTrackingEnabled = limitAdTrackingEnabled; } public String getId() { return this.advertisingId; } public boolean isLimitAdTrackingEnabled() { return this.limitAdTrackingEnabled; } } public static AdInfo getAdvertisingIdInfo(Context context) throws Exception { if (Looper.myLooper() == Looper.getMainLooper()) throw new IllegalStateException( "Cannot be called from the main thread"); try { PackageManager pm = context.getPackageManager(); pm.getPackageInfo("com.android.vending", 0); } catch (Exception e) { throw e; } AdvertisingConnection connection = new AdvertisingConnection(); Intent intent = new Intent( "com.google.android.gms.ads.identifier.service.START"); intent.setPackage("com.google.android.gms"); if (context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) { try { AdvertisingInterface adInterface = new AdvertisingInterface( connection.getBinder()); AdInfo adInfo = new AdInfo(adInterface.getId(), adInterface.isLimitAdTrackingEnabled(true)); return adInfo; } catch (Exception exception) { throw exception; } finally { context.unbindService(connection); } } throw new IOException("Google Play connection failed"); } private static final class AdvertisingConnection implements ServiceConnection { boolean retrieved = false; private final LinkedBlockingQueue<IBinder> queue = new LinkedBlockingQueue<IBinder>( 1); public void onServiceConnected(ComponentName name, IBinder service) { try { this.queue.put(service); } catch (InterruptedException localInterruptedException) { } } public void onServiceDisconnected(ComponentName name) { } public IBinder getBinder() throws InterruptedException { if (this.retrieved) throw new IllegalStateException(); this.retrieved = true; return (IBinder) this.queue.take(); } } private static final class AdvertisingInterface implements IInterface { private IBinder binder; public AdvertisingInterface(IBinder pBinder) { binder = pBinder; } public IBinder asBinder() { return binder; } public String getId() throws RemoteException { Parcel data = http://www.sjsjw.com/100/000336MYM017845/Parcel.obtain(); Parcel reply = Parcel.obtain(); String id; try { data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService"); binder.transact(1, data, reply, 0); reply.readException(); id = reply.readString(); } finally { reply.recycle(); data.recycle(); } return id; } public boolean isLimitAdTrackingEnabled(boolean paramBoolean) throws RemoteException { Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); boolean limitAdTracking; try { data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService"); data.writeInt(paramBoolean ? 1 : 0); binder.transact(2, data, reply, 0); reply.readException(); limitAdTracking = 0 != reply.readInt(); } finally { reply.recycle(); data.recycle(); } return limitAdTracking; } } }
應(yīng)用:
new Thread(new Runnable() { public void run() { try { AdInfo adInfo = AdvertisingIdClient .getAdvertisingIdInfo(MainActivity.this); advertisingId = adInfo.getId(); optOutEnabled = adInfo.isLimitAdTrackingEnabled(); // Log.i("ABC", "advertisingId" + advertisingId); // Log.i("ABC", "optOutEnabled" + optOutEnabled); } catch (Exception e) { e.printStackTrace(); } mHandler.sendEmptyMessage(HANDEL_ADID); } }).start();
相關(guān)案例查看更多
相關(guān)閱讀
- 云南網(wǎng)站建設(shè)報(bào)價(jià)
- 網(wǎng)站搭建
- 小程序分銷(xiāo)商城
- 云南網(wǎng)站建設(shè)案例
- 百度自然排名
- 開(kāi)通微信小程序被騙
- 汽車(chē)回收系統(tǒng)
- 人人商城
- 網(wǎng)站建設(shè)案例
- 云南網(wǎng)站建設(shè)哪家公司好
- 云南etc小程序
- 報(bào)廢車(chē)回收管理系統(tǒng)
- 人口普查小程序
- 楚雄小程序開(kāi)發(fā)
- 小程序表單
- 云南網(wǎng)絡(luò)營(yíng)銷(xiāo)
- 云南網(wǎng)站制作哪家好
- 網(wǎng)站建設(shè)制作
- 南通小程序制作公司
- 網(wǎng)頁(yè)制作
- 云南小程序開(kāi)發(fā)制作公司
- 汽車(chē)報(bào)廢拆解管理系統(tǒng)
- 云南網(wǎng)站建設(shè)電話
- 手機(jī)網(wǎng)站建設(shè)
- 云南衛(wèi)視小程序
- 網(wǎng)絡(luò)公司排名
- 昆明小程序定制開(kāi)發(fā)
- 云南小程序代建
- web開(kāi)發(fā)
- 網(wǎng)絡(luò)公司聯(lián)系方式