日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

通过goole获取手机唯一标识

發(fā)布時間:2024/10/12 编程问答 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 通过goole获取手机唯一标识 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

國內(nèi)的一些方法獲取手機(jī)的唯一標(biāo)識現(xiàn)在7.0之后都不好了,不多說直接上代碼,主要是根據(jù)goole商店

import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.pm.PackageManager; import android.os.IBinder; import android.os.IInterface; import android.os.Looper; import android.os.Parcel; import android.os.RemoteException;import java.util.concurrent.LinkedBlockingQueue;public class AdvertisingIdClient {/*** 這個方法是耗時的,不能在主線程調(diào)用*/public static String getGoogleAdId(Context context) throws Exception {if (Looper.getMainLooper() == Looper.myLooper()) {return "Cannot call in the main thread, You must call in the other thread";}PackageManager pm = context.getPackageManager();pm.getPackageInfo("com.android.vending", 0);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());return adInterface.getId();} finally {context.unbindService(connection);}}return "";}private static final class AdvertisingConnection implements ServiceConnection {boolean retrieved = false;private final LinkedBlockingQueue<IBinder> queue = new LinkedBlockingQueue<>(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 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 = 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;}} }

在main?里面直接調(diào)用

Executors.newSingleThreadExecutor().execute(new Runnable() {@Overridepublic void run() {try {adid = AdvertisingIdClient.getGoogleAdId(com.facebook.FacebookSdk.getApplicationContext());Log.e("MainActivity", "adid: " + adid);} catch (Exception e) {e.printStackTrace();}} });

?

總結(jié)

以上是生活随笔為你收集整理的通过goole获取手机唯一标识的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。