'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 1:[1]
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.
Solution 2:[2]
You can use the same Test ID multiple times. But make sure to replace it with a real one before launching. Real ones cannot be called multiple times (unless if you dispose them before using them somewhere else) so create new ones accordingly
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | YaDev |