Download Code

Xamarin Google Admob Example Android

AdMob by Google is a mobile advertising platform that you can use to generate revenue from your app.It’s multi platform ads network like Android,IO’s etc.There are basically four types of Admob ads but two types mostly used in apps.In xamarin google admob example android tutorial you will learn how to integrate google admob ads in android.

  • Banner
  • Interstitial
  • Rewarded Interstitial
  • Native

First you will need an id of ads to integrate Google Admob ads for that purpose do the following steps.

  • Sign Up for Admob Account from Website.
  • Next go to Monetize menu option.
  • Click on Monetize new app button on left top corner.
  • Next click on Add your app manually.
  • Add app name and select platform(Android).
  • After adding app it will generate an ads id(ca-app-pub-3940256099942544/6300978111).
  • Then select ad format(Banner,Interstitial) and ad unit name.
  • At last Save and Done.

Create new xamarin google admob example android application project.Import Google Play Services Library(Ads) by right clicking on components and add.Go to Main.axml  and add  google adView.This is the code to integrate google admob ads of type BANNER.

Main.axml

xamarin google admob,xamarin google admob example,xamarin google admob example android,google admob example android,

Alright When you are testing ads don’t test real ads.Why because when you click on real ads again and again.Admob will disable your Admob Account.

MainActivity.cs

namespace XamarinAdmob
{
	[Activity(Label = "XamarinAdmob", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity : Activity
	{
		protected AdView mAdView;
		private InterstitialAd interstitialAds = null;

		protected override void OnCreate(Bundle savedInstanceState)
		{
			base.OnCreate(savedInstanceState);

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Main);
			interstitialAds = new InterstitialAd(this);   // initializing interstitial ads 
			mAdView = FindViewById(Resource.Id.adView);
			var adRequest = new AdRequest.Builder().Build();
			mAdView.LoadAd(adRequest);
			// setting unit id for interstitial ad
			interstitialAds.AdUnitId = "ca-app-pub-3940256099942544/1033173712";
			// loading test ad using adrequest
			interstitialAds.LoadAd(adRequest);

			interstitialAds.AdListener = new AdListener(this);


		}
		class AdListener : Android.Gms.Ads.AdListener
		{
			MainActivity main;

			public AdListener(MainActivity innerMain)
			{
				main = innerMain;
			}

			public override void OnAdLoaded()
			{
				base.OnAdLoaded();
				main.interstitialAds.Show();
			}
		}
	}
}

Android Manifest.xml

xamarin google admob,xamarin google admob example,xamarin google admob example android,google admob example android,

Run your android application project.

xamarin google admob,xamarin google admob example,xamarin google admob example android,google admob example android,

That’s it for this tutorial.

For Java example visit Android Codec.

Thanks.