admin 7798
admin 7798

Reputation: 697

Actual Ads showing instead of Test Ads in Admob

I a seeing actual ads instead of test ads in my app. Check out the image and code.enter image description here

AdView mAdView = (AdView) findViewById(R.id.adView);
    //AdRequest adRequest = new AdRequest.Builder().build();
    AdRequest request = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)        // All emulators
            .addTestDevice("32F40C185F4A9214").addTestDevice("31B340D6693D6C01").addTestDevice("759E79391A5A27C3")
            .addTestDevice("aa6705960ab37b0d")
            .build();
    mAdView.loadAd(request);

Upvotes: 2

Views: 654

Answers (3)

Ravi
Ravi

Reputation: 35589

Your Device Id might be wrong.

Add test deviceId like this, so you don't need to replace it when device change.

.addTestDevice(getDeviceId(context))

Code for getDeviceId() and md5()

public static String getDeviceId(Context context)
{
    String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    String deviceId = md5(android_id).toUpperCase();
    //return deviceId;
    return "0";
}

public static final String md5(final String s) {
    try {
        // Create MD5 Hash
        MessageDigest digest = java.security.MessageDigest
                .getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            String h = Integer.toHexString(0xFF & messageDigest[i]);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

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

Upvotes: 1

Souhaieb Besbes
Souhaieb Besbes

Reputation: 1504

from the androidcookbook admob tutorial

When integrating AdMob ads into your application it is recommended to use test mode. In test mode test, ads are always returned. Test mode is enabled on a per-device basis. To enable test mode for a device, first request an ad, then look in LogCat for a line like the following:

To get test ads on the emulator use AdManager.setTestDevices...

Once you have the device ID you can enable test mode by calling in your main activity AdManager.setTestDevices:

AdManager.setTestDevices( new String[] { AdManager.TEST_EMULATOR, "E83D20734F72FB3108F104ABC0FFC738", //Phone ID } );

Comparing the two screenshots, it's looks to me that your program is correctly configured for test mode.

Upvotes: 0

Ibrahim Gharyali
Ibrahim Gharyali

Reputation: 564

Are you sure out of this 4 device id's there is one valid id of your device?

please check in your logs, Admob prints your device id in it. Put the same device id in addTestDevice();

Upvotes: 3

Related Questions