当前位置:   article > 正文

如何获取Admob需要的的test device ID_adinternalsettings.addtestdevice 如何获取

adinternalsettings.addtestdevice 如何获取

官方指南说


请求一个广告就会打印id出来


he alternative way of serving test ads is to keep your regular ad unit ID, but configure your device as a test device. When a device is configured as a test device, the Google Mobile Ads SDK automatically substitutes in the aforementioned sample ad unit ID, limiting that device to receiving test ads.


Follow the steps below to configure your device as a test device.


Note: Android emulators are automatically configured as test devices.
Add your test device


Load your ads-integrated app and make an ad request.
Check the logcat output for a message that looks like this:
I/Ads: Use AdRequest.Builder.addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
to get test ads on this device.
Copy your test device ID to your clipboard.
Modify your code to call AdRequest.Builder.addTestDevice() with your test device ID. This method can be called multiple times for multiple devices.
AdRequest request = new AdRequest.Builder()
    .addTestDevice("33BE2250B43518CCDA7DE426D04EE232")
    .build();
You can optionally check request.isTestDevice() to confirm that your device was properly added as a test device.


Note: Be sure to remove the code that sets these test devices before you release your app.




但是我的手机没输出

酷派的手机好像 屏蔽了i级别的打印.


下面是网上查到的方法, 用代码获取id.


源地址


The accepted answers will work if you are only testing on the Emulator or on a few devices, but if you are testing on a plethora of devices, you may need some means of prorammatically adding the running device's device ID.


The following code will make the current running device into an adview test device programmatically

  1. if(YourApplication.debugEnabled(this)) //debug flag from somewhere that you set
  2. {
  3. String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
  4. String deviceId = md5(android_id).toUpperCase();
  5. mAdRequest.addTestDevice(deviceId);
  6. boolean isTestDevice = mAdRequest.isTestDevice(this);
  7. Log.v(TAG, "is Admob Test Device ? "+deviceId+" "+isTestDevice); //to confirm it worked
  8. }
You need to use the md5 of the Android ID, and it needs to be upper case. Here is the md5 code I used

  1. public static final String md5(final String s) {
  2. try {
  3. // Create MD5 Hash
  4. MessageDigest digest = java.security.MessageDigest
  5. .getInstance("MD5");
  6. digest.update(s.getBytes());
  7. byte messageDigest[] = digest.digest();
  8. // Create Hex String
  9. StringBuffer hexString = new StringBuffer();
  10. for (int i = 0; i < messageDigest.length; i++) {
  11. String h = Integer.toHexString(0xFF & messageDigest[i]);
  12. while (h.length() < 2)
  13. h = "0" + h;
  14. hexString.append(h);
  15. }
  16. return hexString.toString();
  17. } catch (NoSuchAlgorithmException e) {
  18. Logger.logStackTrace(TAG,e);
  19. }
  20. return "";
  21. }

我用其他人的一加手机测试, 获得的ID和logcat打印的是一样的.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/198762
推荐阅读
相关标签
  

闽ICP备14008679号