0

I have trying to show full screen ads in my app using following code:

AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
AdRequest adRequest = adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(this.getText(R.string.full_screen_ad_unit_id).toString());
interstitial.loadAd(adRequest);


if(interstitial.isLoaded()) 
{
    interstitial.show();
}

But in emulator and in real device adMob showing the live ads instead of test ads.

This will create major problem for me i.e. it may block my admob account because of invalid impression or invalid clicks.

I have following this tutorial.

So please help me to resolve this problem?

DevK
  • 145
  • 2
  • 13
  • Try this >>- AdRequest adRequest = adRequestBuilder.addTestDevice("CD0005AF3FFA73AC718D23D8CC419110").build(); – Md Abdul Gafur Jan 08 '15 at 09:04
  • @MdAbdulGafur These types of ids are specific to device. This will not work on different devices. And I have already tries "3B361E14CEFB340462CDE8F77C97EC87" id that was admob recommend in eclipse logcat. But this id only work on that device not in another. And I don't want change this id myself when I changed device. – DevK Jan 08 '15 at 09:08

1 Answers1

0

I got a alternative method to solve this issue. Working code is:

AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
AdRequest adRequest;
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = Utilities.getMD5(android_id).toUpperCase(Locale.ENGLISH);

adRequest = adRequestBuilder.addTestDevice(deviceId).build();
boolean isTestDevice = adRequest.isTestDevice(this);

SetLogInfo.writeLog1("is Admob Test Device ? "+deviceId+" "+isTestDevice);

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(this.getText(R.string.full_screen_ad_unit_id).toString());
interstitial.loadAd(adRequest);


if(interstitial.isLoaded()) 
{
interstitial.show();
}

And getMD5():

protected static String getMD5(String inputText)
{
    String md5 = "";
    try
    {
        MessageDigest digester = MessageDigest.getInstance("MD5");
        digester.update(inputText.getBytes());
        md5 = new BigInteger(1, digester.digest()).toString(16);
    }
    catch(Exception e)
    {
        SetLogInfo.writeLog("Exception: "+e);
    }
    return md5;
}

At least this solution is best instead of using "AdRequest.DEVICE_ID_EMULATOR". Got idea from here

Community
  • 1
  • 1
DevK
  • 145
  • 2
  • 13