当前位置:网站首页>获取Google Advertising ID作为唯一识别码
获取Google Advertising ID作为唯一识别码
2022-07-30 13:45:00 【互联网小熊猫】
一、背景
在Android程序中,有时候我们APP需要获取唯一识别码,来区别用户。在Android系统中提供了了AndroidId,但AndroidId有时候会为null,同时root手机用户,androidid可以改变。所以AndroidId并不能作为唯一识别码。
对于Google推荐使用Google Advertising ID,通过Google Service可以获取Google Advertising ID(如果没有Google Service就回去不到Google Advertising ID)。
二、代码实现
/** * 这个方法是耗时的,不能在主线程调用 */
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";
}
AdvertisingIdClient.Info idInfo = null;
try {
idInfo = AdvertisingIdClient.getAdvertisingIdInfo(ctx);
} catch (IOException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
}
String adid = null;
try {
if (idInfo != null) {
adid = idInfo.getId();
}
} catch (NullPointerException e) {
e.printStackTrace();
}
return adid;
}
边栏推荐
- 接口自动化框架,lm-easytest内测版发布,赶紧用起来~
- 逻辑漏洞----权限类漏洞
- sql中ddl和dml(sql与access的区别)
- 新一代开源免费的终端工具,太酷了
- 自动化测试之数据驱动DDT详细篇
- 百家号取消接口发文功能:插外链获权重被堵死
- Logic Vulnerability----Permission Vulnerability
- 时间序列的数据分析(四):STL分解
- CF1677E Tokitsukaze and Beautiful Subsegments
- ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
猜你喜欢

重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践

业内人士真心话:只会测试没有前途的,我慌了......

戴墨镜的卡通太阳SVG动画js特效

Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics

阿里 P7 到底是怎样的水平?

六面蚂蚁金服,抗住面试官的狂轰乱炸,前来面试复盘

第十五天笔记

一本通循环结构的程序设计题解(2)

05 | login background: based on the password login mode (below)

打破原则引入SQL,MongoDB到底想要干啥???
随机推荐
CF780G Andryusha and Nervous Barriers
第十四天笔记
shell script flow control statement
libudev manual
【软考软件评测师】自动化测试章节下篇
UPC2022暑期个人训练赛第19场(B,P)
Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
LeetCode二叉树系列——102.二叉树的层序遍历
How awesome is the "12306" architecture?
redis6.0 源码学习(五)ziplist
ENVI Image Processing (6): NDVI and Vegetation Index
The path to uniting the programmer: "titles bucket" to the highest state of pragmatic
LeetCode二叉树系列——515.最每个树行中找最大值
MIMO雷达波形设计
pytorch学习记录(六):循环神经网络 RNN & LSTM
重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
Composer安装方式
20220729 Securities, Finance
CF1677E Tokitsukaze and Beautiful Subsegments
Jenkins自动化部署项目