当前位置:网站首页>Get the Google Advertising ID as a unique identifier
Get the Google Advertising ID as a unique identifier
2022-07-30 14:35:00 【Internet Red Panda】
一、背景
在Android程序中,有时候我们APPA unique identification code is required,to distinguish users.在Androidprovided in the systemAndroidId,但AndroidId有时候会为null,同时root手机用户,androidid可以改变.所以AndroidIdNot as a unique identifier.
对于Google推荐使用Google Advertising ID,通过Google Service可以获取Google Advertising ID(如果没有Google ServiceI can't go backGoogle Advertising ID).
二、代码实现
/** * This method is time consuming,Cannot be called on the main thread */
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;
}
边栏推荐
- LeetCode二叉树系列——515.最每个树行中找最大值
- 如何在 TiDB Cloud 上使用 Databricks 进行数据分析 | TiDB Cloud 使用指南
- Chapter6 : Has Artificial Intelligence Impacted Drug Discovery?
- Web3创始人和建设者必备指南:如何构建适合的社区?
- selenium4+pyetsst+allure+pom进行自动化测试框架的最新设计
- Hello,World
- The path to uniting the programmer: "titles bucket" to the highest state of pragmatic
- [VMware virtual machine installation mysql5.7 tutorial]
- (HR面试)最常见的面试问题和技巧性答复
- What should I do if the sql server installation fails (what should I do if the sql server cannot be installed)
猜你喜欢

还在说软件测试没有中年危机?9年测试工程师惨遭淘汰

开源工具推荐:高性能计算辅助工具MegPeak

NFTScan 与 PANews 联合发布多链 NFT 数据分析报告

OFDM Sixteen Lectures 3- OFDM Waveforms

Before quitting, make yourself a roll king

Application of time series database in the field of ship risk management

记面试外包公司的一次经历,到底该不该去?

LeetCode二叉树系列——199二叉树的右视图

激光雷达点云语义分割论文阅读小结

Shell变量与赋值、变量运算、特殊变量、重定向与管渠
随机推荐
浅析显卡市场的未来走向:现在可以抄底了吗?
mongodb打破原则引入SQL,它到底想要干啥?
No-code development platform all application settings introductory tutorial
sql中ddl和dml(sql与access的区别)
网站添加能换装可互动的live 2d看板娘
pytorch学习记录(五):卷积神经网络的实现
There is a risk of water ingress in the battery pack tray and there is a potential safety hazard. 52,928 Tang DMs are urgently recalled
关于容器的小案例
Machine learning difference in the competition and industry application
Web3创始人和建设者必备指南:如何构建适合的社区?
cookie模拟登录「建议收藏」
Flask Framework - Flask-Mail Mail
开始学习C语言了
新时代背景下智慧城市的建设与5G技术有何关联
The main content of terrain analysis (the special effect level of the wandering earth)
Eclipse connects to SQL server database "recommended collection"
ECCV 2022 | 通往数据高效的Transformer目标检测器
Baijiahao cancels the function of posting documents on the interface: the weight of the plug-in chain is blocked
CF1677E Tokitsukaze and Beautiful Subsegments
A Small Case About Containers