Search code examples
flutteradmob

Flutter - Using multiple Test Id for Admob Banner


I wanted to add some Admob Banner in my Flutter app (using the offical Admob package https://pub.dev/packages/google_mobile_ads)

Flutter Admob guide only provide 1 Test ID for iOS and another for Android, what can I do if I need multiple Test ID in my app?


Solution

  • Finally found the solution. I have summarised the steps below for anyone who wants to know how to use multiple IDs in Flutter (this might be common since Flutter users is likely to place Ads in ListView). I have also added some reading reference below.

    In summary:

    • Use your own Ads Id (not Test Id)
    • Run an Ads in your actual Device to obtain the Test Device ID. This is automatically print out when the ads is called. Find the text similar to the example shown below:

    RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("The code you want to copy")) to get test ads on this device."

    • Use the code below to initialised Admob to provide Test Ads. Call the code before you initialised Admob.
    • You will observe actual Ads but with a "Test Ads" text on top.

    Code to initialised Test Ads for Flutter:

    //"The code you want to copy" is the code that you extract from your log based on earlier steps
    List<String> testDeviceIds = "The code you want to copy";
    
    RequestConfiguration configuration = RequestConfiguration(
        testDeviceIds: testDeviceIds);
    MobileAds.instance.updateRequestConfiguration(configuration);
    

    Reading material for reference:

    Reference to Admob Test Ads for native Android if you are interested - link. They should add documentation for Flutter.

    Reference to the code from another post which provide the code by answering a different question. Here is the link.