Skip to main content

When AdMob ads are not displayed in an app developed with Xamarin.Forms

   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.

Test ads must appear unconditionally!


  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

Popular posts from this blog

Card payment error when registering as a Google developer (OR-CCSEH-22)

   When registering as a developer on the Google Play console, you have to pay by card in the payment window, but the payment error still occurred even though the credit card number that is being used well both domestically and abroad was correctly entered.   The error message at that time was "The request has failed. Use a different payment method or contact your bank. Learn more [OR-CCSEH-22]".    The same error continued to occur even with other PCs and tablets, and even searching the Internet could not find a solution.     In the end, it was resolved immediately by paying with a different credit card.    There is no solution with an erroneous credit card. Credit card in the name of another person is also irrelevant, so pay with another card.