当前位置:网站首页>获取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;
}
边栏推荐
- UPC2022暑期个人训练赛第19场(B,P)
- strlen跟sizeof区别
- LeetCode二叉树系列——199二叉树的右视图
- 无代码开发平台应用可见权限设置入门教程
- [论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
- CF603E Pastoral Oddities
- Learning notes - 7 weeks as data analyst "in the first week: data analysis of thinking"
- Skywalking入门
- LeetCode二叉树系列——144.二叉树的最小深度
- CF1320E Treeland and Viruses
猜你喜欢
随机推荐
HCIP(第十五天) —— 交换机(一)
ML之PDP:基于FIFA 2018 Statistics(2018年俄罗斯世界杯足球赛)球队比赛之星分类预测数据集利用DT决策树&RF随机森林+PDP部分依赖图可视化实现模型可解释性之详细攻略
CF780G Andryusha and Nervous Barriers
jsArray数组复制方法性能测试2207292307
canvas彩虹桥动画js特效
The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism
05 | 后台登录:基于账号密码的登录方式(下)
R语言使用aov函数进行单因素协方差分析(One-way ANCOVA)、使用effects包中的effect函数来计算调整后的分组均值(calculate adjusted means)
近两年激光雷达运动物体分割论文阅读小结
自动化测试之数据驱动DDT详细篇
为什么做软件测试一定要学自动化?谈谈我眼中自动化测试的价值
时间序列的数据分析(四):STL分解
LeetCode二叉树系列——144.二叉树的最大深度
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
#第九章 子查询课后习题
ARC115F Migration
ccs软件的使用(靠谱挣钱的app软件)
sql中ddl和dml(sql与access的区别)
“封号斗罗” 程序员修炼之道:通向务实的最高境界
(HR面试)最常见的面试问题和技巧性答复








