Java android获取adMob的设备ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9681400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 06:05:38  来源:igfitidea点击:

android get device ID for adMob

javaandroideclipseadmob

提问by Jaume

Possible Duplicate:
How can I get device ID for Admob

可能重复:
如何获取 Admob 的设备 ID

I am testing adMob on my android device and following with documentation, I am trying to get device ID executing adRequest. However, I am not able to find device ID in the logCat! What I am doing wrong?

我正在我的 android 设备上测试 adMob 并遵循文档,我试图获取执行 adRequest 的设备 ID。但是,我无法在 logCat 中找到设备 ID!我做错了什么?

 AdRequest adRequest = new AdRequest();
 adRequest.addTestDevice(AdRequest.TEST_EMULATOR);            
 adRequest.addTestDevice("test");     

Edit: it is not a duplicate, those methods from other post are not working for me.

编辑:它不是重复的,其他帖子中的那些方法对我不起作用。

采纳答案by Pradeep Sodhi

 final TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

String deviceid = tm.getDeviceId();

回答by Aracem

In android < 4

在安卓 < 4

How to find serial number of Android device?

如何找到Android设备的序列号?

In the new Android 4.0+ you can find the id number in the Settings --> Developer Options

在新的 Android 4.0+ 中,您可以在 Settings --> Developer Options 中找到 ID 号

回答by Eric Leichtenschlag

Make a live ad request while running on the device, and view the logs. There should be a log at the info level that says:

在设备上运行时发出实时广告请求,并查看日志。信息级别应该有一个日志,上面写着:

I/Ads: To get test ads on this device, call adRequest.addTestDevice("YOUR_HASHED_DEVICE_ID");

I/Ads: To get test ads on this device, call adRequest.addTestDevice("YOUR_HASHED_DEVICE_ID");

Since the SDK hashes your device ID, it is much easier and cleaner to grab this number directly through the logs rather than bothering to try to grab the Android device ID, and doing some manual hashing to try to get this same number.

由于 SDK 会对您的设备 ID 进行哈希处理,因此直接通过日志获取这个数字会更容易、更清晰,而不是费心去尝试获取 Android 设备 ID,并进行一些手动哈希来尝试获取相同的数字。