3

I'm making an application including admob ads with help of this google's official tutorial

However, it states "You should always use test ads when developing and testing your app--testing with live production ads is a violation of AdMob policy and could cause your account to be suspended".

So I now have a test and a production Ad Unit ID. Should I manually switch my code to production/test id during my application release process or is there an kind of automatic for this?

Thank you

gadjou
  • 88
  • 7

2 Answers2

2

you can use the production Ad Unit ID for your testing. just include the test device and it'll automatically load the test ads.

private static final String TEST_DEVICE ="xxxx..."; //see Log cat for the value.

AdRequest adrequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(TEST_DEVICE)
            .build();

if (adview !=null)
       adview.loadAd(adRequest);

see this post on how to get the TEST_DEVICE id How can I get device ID for Admob

Community
  • 1
  • 1
Angel Koh
  • 12,479
  • 7
  • 64
  • 91
  • I am testing production Ad Unit ID on real android device. Do I need to use .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) line or remove it. – Anbarasu Chinna Jul 03 '20 at 06:46
0

You have to switch ad IDs for test and production when making a build. You can simply put this code and it'll switch test unit ID if you are in debug mode and production when you make a 'release':

String intersProd_ID="<your admob production ID";
String intersTest_ID="<admob test unit ID";
String useInters;

        if((BuildConfig.DEBUG)){
            useInters = intersTest_ID;
        }
        else{
            useInters = intersProd_ID;
        }
tariq101
  • 127
  • 2
  • 6