1

i added admob ad in my application, the device id required for admob i find by following code,

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

Rajesh Panchal
  • 1,140
  • 3
  • 20
  • 39
  • Device id required only for showing test ads,not in deployment. – Giru Bhai Oct 10 '14 at 04:40
  • so, what should i pass as parameter in "device_id" AdRequest adRequest = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .addTestDevice(device_id) .build(); // adView.loadAd(adRequest); – Rajesh Panchal Oct 10 '14 at 05:01
  • do you want to display test ad? – Giru Bhai Oct 10 '14 at 05:02
  • no i want to implement admob in my app and upload it to play store so that any user downloads my app from play store admob should work on all those devices – Rajesh Panchal Oct 10 '14 at 05:06

3 Answers3

2

addTestDevice is used for showing Admob test ads for development.so in deployment remove addTestDevice from your adRequest,i.e. make your adRequest as

   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

AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(device_id)
                .build();
adView.loadAd(adRequest);
Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
1

It is mentioned on the official tutorial page with link - https://developers.google.com/mobile-ads-sdk/docs/admob/android/banner That

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.

Means your device ID will be similarly shown. The above one is just an example id.

Kunalxigxag
  • 728
  • 4
  • 12
0

Just go to your Log Cat and search "Ads". Then you will find your device then just use it like.

AdRequest request = new AdRequest.Builder()
.addTestDevice("Device ID")
.build();
pavel
  • 1,603
  • 22
  • 19