How to make AdMob work with the latest MG?

Hi @tonyyy ,

The code below looks kind of messy, but it works for me.

Inside Activity1.cs:

public class Activity1 : Microsoft.Xna.Framework.AndroidGameActivity
    {
		private AdView bannerAd;
		public AdView BannerAd {
			get { return bannerAd; }
		}
		private static InterstitialAd interstitial;
		private const string bannerID = "your banner id";
		private const string interstitialID = "your interstitial id";
		private const string testDeviceID = "your test device id";
		private LinearLayout ll;
		private FrameLayout fl;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
			SupportClass.Version = GetCurrentAppVersion ();
            var g = new Game1(this);

			interstitial = AdWrapper.ConstructFullPageAd(this, interstitialID);

			fl = new FrameLayout (this);
			fl.AddView ((View)g.Services.GetService (typeof(View)));
            
			CreateBannerAd();

			SetContentView(fl);
            g.Run();
        }

		public void CreateBannerAd()
		{
			if (ll == null)
			{
				HideBannerAd();
				ll = new LinearLayout(this);
				ll.Orientation = Orientation.Horizontal;
				ll.SetGravity(GravityFlags.Left | GravityFlags.Bottom);

				bannerAd = new AdView(this);
				bannerAd.AdSize = AdSize.Banner;
				bannerAd.AdUnitId = bannerID;
				ll.AddView(bannerAd);
				fl.AddView(ll);
			}

			bannerAd.CustomBuild (testDeviceID);
		}

		public void HideBannerAd()
		{
			if (ll != null)
			{
				fl.RemoveView(ll);
				ll.RemoveView(bannerAd);
				bannerAd.Dispose();
				bannerAd = null;
				ll.Dispose();
				ll = null;
			}
		}

		public void ShowInterstitialAd()
		{
			RunOnUiThread(() =>
				{
					if (interstitial.AdListener != null)
						interstitial.AdListener.Dispose();
					interstitial.AdListener = null;
					var intlistener = new adlistener();
					intlistener.AdLoaded += () => { if (interstitial.IsLoaded)interstitial.Show(); };
					interstitial.AdListener = intlistener;

					interstitial.CustomBuild(testDeviceID);
				});
		}
    }

Inside AdWrapper.cs:

internal static class AdWrapper
	{
		public static InterstitialAd ConstructFullPageAd(Context con, string UnitID)
		{
			var ad = new InterstitialAd(con);
			ad.AdUnitId = UnitID;
			return ad;
		}

		public static AdView ConstructStandardBanner(Context con, AdSize adsize, string UnitID)
		{
			var ad = new AdView(con);
			ad.AdSize = adsize;
			ad.AdUnitId = UnitID;
			return ad;
		}

		public static InterstitialAd CustomBuild(this InterstitialAd ad, string testDeviceID)
		{
			var requestbuilder = new AdRequest.Builder()
				.AddTestDevice(AdRequest.DeviceIdEmulator)
				.AddTestDevice(testDeviceID)
				.Build();
			ad.LoadAd(requestbuilder);
			return ad;
		}

		public static AdView CustomBuild(this AdView ad, string testDeviceID)
		{
			var requestbuilder = new AdRequest.Builder()
				.AddTestDevice(AdRequest.DeviceIdEmulator)
				.AddTestDevice(testDeviceID)
				.Build();
			ad.LoadAd(requestbuilder);
			return ad;
		}
	}

Whenever you want to create a banner/interstitial, just call the CreateBannerAd() method or the ShowInterstitial() method in Activity1. If you want to hide the banner ad, call the HideBannerAd() method. That’s it!