After developing an app with Xamarin.Forms for a long time, I registered AdMob as well, and when I tested it on a test device, advertisements were sometimes displayed. However, it seems that there were more times when the advertisement was not shown.
Even though I launched the app on the Play Store, I still didn't see any ads, so I searched the internet for a number of reasons.
In conclusion, the test advertisement should appear straight on the device registered as a test device with AdMob.
I went through two methods, but the first would be the direct cause, and the second could not be said to have no effect.
Grid height fixed
I set the height of the ad area to Auto on the page where the ad is displayed (the third row in the source below), but there were quite a few people that this did not work properly in AdMob ads.
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
....
<Grid Grid.Row="2">
<local:AdMobView AdUnitId="//Ad Unit ID//"/>
</Grid>
Just specify a fixed value as shown below.
<RowDefinition Height="70"/>
MobileAds.Initialize
How to attach AdMob ads to Xamarin.Forms apps is well known on the Internet, but most of them are wrong.
It is said to be put in Oncreate of MainActivity.cs as follows.
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
MobileAds.Initialize(ApplicationContext, "//APPLICATION_ID//");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
MobileAds.Initialize(ApplicationContext, "//APPLICATION_ID//");
It is said that this part is no longer used.
Application ID is registered in AndroidManifest.xml, so you can just use it as follows.
MobileAds.Initialize(this);
Conclusion
As soon as it is modified and distributed as above, the test advertisement appears well.
However, on a general device that is not a test device, it is about 6 hours, so the normal advertisement appears well.

Comments
Post a Comment