简体   繁体   English

如何获取Admob的设备ID

[英]How to get Device id for Admob

i added admob ad in my application, the device id required for admob i find by following code, 我在应用程序中添加了admob广告,我通过以下代码找到了admob所需的设备ID,

String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
device_id = md5(android_id).toUpperCase();

public static String md5(String s) {
    try {

        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();


        StringBuffer hexString = new StringBuffer();
        for (int i=0; i<messageDigest.length; i++)
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return "";
}

The problem with this is that its showing ads on some devices but on some devices it shows test ads. 问题是它在某些设备上显示广告,但在某些设备上显示测试广告。 where am i wrong?? 我在哪里错了? pls help 请帮助

addTestDevice is used for showing Admob test ads for development.so in deployment remove addTestDevice from your adRequest ,ie make your adRequest as addTestDevice用于显示要开发的Admob测试广告。因此在部署中,从adRequest删除addTestDeviceadRequest adRequest

   AdRequest adRequest = new AdRequest.Builder().build();
   adView.loadAd(adRequest);

And if you want to get device id for testing then see this How can I get device ID for Admob Then add addTestDevice in adRequest as 而且,如果您想获取用于测试的设备ID,请参阅此如何获取Admob的设备ID,然后在addTestDevice中添加adRequest作为

AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(device_id)
                .build();
adView.loadAd(adRequest);

It is mentioned on the official tutorial page with link - https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner That 它在官方教程页面上通过链接进行了提及-https: //developers.google.com/mobile-ads-sdk/docs/admob/android/banner

logcat will print the device's MD5-hashed ID for convenience, for example: Use AdRequest.Builder.addTestDevice("AC98C820A50B4AD8A2106EDE96FB87D4") to get test ads on this device. 为了方便起见,logcat会打印设备的MD5哈希ID,例如:使用AdRequest.Builder.addTestDevice(“ AC98C820A50B4AD8A2106EDE96FB87D4”)在此设备上获取测试广告。

Means your device ID will be similarly shown. 意味着您的设备ID将类似显示。 The above one is just an example id. 上面的只是一个示例ID。

Just go to your Log Cat and search "Ads". 只需转到Log Cat,然后搜索“广告”。 Then you will find your device then just use it like. 然后,您将找到设备,然后像使用它一样。

AdRequest request = new AdRequest.Builder()
.addTestDevice("Device ID")
.build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM