当前位置:网站首页>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;
}
边栏推荐
- CF1320E Treeland and Viruses
- Some thoughts on String
- Interface automation framework, lm-easytest beta version released, use it quickly~
- The main content of terrain analysis (the special effect level of the wandering earth)
- 3年软件测试经验面试要求月薪22K,明显感觉他背了很多面试题...
- 新一代开源免费的终端工具,太酷了
- A simple change for problem, knapsack problem sets of shell
- 手把手教你写让人眼前一亮的软件测试简历,收不到面试邀请算我输
- 国内数字藏品的乱象与未来
- Classic test interview questions set - logical reasoning questions
猜你喜欢
VLAN实验
A simple change for problem, knapsack problem sets of shell
Interface automation framework, lm-easytest beta version released, use it quickly~
深入浅出零钱兑换问题——背包问题的套壳
mongodb打破原则引入SQL,它到底想要干啥?
pytorch学习记录(六):循环神经网络 RNN & LSTM
LeetCode二叉树系列——144.二叉树的最大深度
激光雷达点云语义分割论文阅读小结
MQTT网关读取西门子PLC数据传输到阿里云平台案例教程
从实例来看DAO:权力分散的伟大尝试
随机推荐
EasyV数字孪生流域|宁波智慧水利整体智治综合应用
Flask框架——Flask-SQLite数据库
LeetCode二叉树系列——116.填充每个节点的下一个右侧指针
OFDM 十六讲 3- OFDM Waveforms
DocuWare 文件管理与工作流程自动化案例研究——DocuWare 工作流程功能使在家工作的员工能够保持沟通和高效工作,支持混合环境
Hello,World
Web消息推送之SSE
【Pytorch】如何在关闭batch-norm的同时保持Dropout的开启
Skywalking入门
Synology system installation related file sharing
激光雷达点云语义分割论文阅读小结
Application of time series database in the field of ship risk management
43.【list的简单属性】
Still saying software testing doesn't have a midlife crisis?9 years of test engineers were eliminated
CF1320E Treeland and Viruses
浅析显卡市场的未来走向:现在可以抄底了吗?
业内人士真心话:只会测试没有前途的,我慌了......
Desktop Software Development Framework Awards
时间序列的数据分析(四):STL分解
Jenkins自动化部署项目