Useful Tips

How to add ads to your Android application using Admob

Almost every developer who has finished working on his application and wants to publish his creation on Google Play reaches the question regarding adding ads to android applications. To resolve this issue, this article was created.

So, the first thing you need to do is sign up for Admob. This can be done by clicking on the link https://www.google.com/admob/. After you log in to your account, click on the button Monetize new app (Monetize New Application). For the type of advertisement, select Banner and copy the ad unit identifier issued to you somewhere.

Now let's get down to the project. Create a new project or use an existing one.

I will assume that you are using Android Studio and Gradle as a collector. To work with Google Play services, you need to add the necessary libraries to the project. Copy this line and add to the dependencies section:

compile ‘Com.google.android.gms: play-services-ads: 8.4.0’

Between tags and add the following lines:

Monetize your app with AdMob

Before we can integrate the SDK, we need to create our application in AdMob. If you don’t have an AdMob account yet, now is the time to create one. After the account is created, you can simply click on the Monetize App button to find your application in the application store or add it manually. You should select Manual mode if you have not already placed the application on Google Play.

The next step is to choose the advertising format that we want to integrate into the application. The simplest ad format is a banner, which is placed along the application. We have control over how often ads will be displayed and on what type of advertising will be present in them. Then we can bind Firebase for advanced analytics or skip this item.

At this point, we can add additional ad units or get installation instructions. If we want to add banners to many Activities, then creating ad units for each of them will be a great practice. Returning to the main screen of the application, we must write down the application identifier and the ad unit identifier for integration in the code:

Getting started with the Ads Lite SDK

Ads Lite is a brand new SDK that was introduced with Google Play services 9.6.1. This developer kit has far fewer dependencies than the standard Ads SDK, but it still requires a minimum version of the 24.2.1 Android support libraries. This means that Ads Lite is currently - at the time of this writing - incompatible with Xamarin.Forms applications (for that matter, check out my material on adding ads to Xamarin.Forms applications). However, Ads Lite can be easily added to traditional Xamarin.Android applications using the NuGet package.

Adding Permissions and Activity Ads

After the SDK is added, we need to update our Android Manifest with several permissions and default advertising activity so that the service can be launched.

For the Google Mobile Ads Lite SDK to work correctly, the following permissions are required: Internet and Access Network State. We can add them with the following assembly level attributes: