Adding Ads to Android App
Adding Google’s Admob Ads to Android Studio App
If you’ve never been used Admob for advertising an App, you properly need to go first to Google’s Admob Website and sign up for an Admob account:
Creating the Ad on Admob
If your App is brand new, you need to choose “Add your app manually” from the tabs.
And fill in the package name. I am using for this example the app BMI Calculator from the last tutorial that has the package name “com.greendog.example.bmiapp”
Choose “Android” as platform and click on <Add app>.
Here you can choose between Banner and Interstitial Ads.
Banners are small impressions that can be customized in size. The size will be defined later in Android Studio. More info at Google Developer.
Interstitial Ads are fullscreen Ads. More info at Google Developer.
I will continue with Banners in this example and use the App BMI Calculator from this tutorial.
After clicking <Save> you will get your publisher code for this Ad. You need to copy this code (Ad unit ID).
Now head over to Android Studio. The best way to start is, to add the Ad unit ID into the strings.xml like this.
Next open the build.gradle file of your project and add the following library entry to use Admob Ads.
Now, we’re going to add the needed code to the layout file where we want to show the Ad.
There’re two parts. First, you need a second xmlms line that allows you to call adds.
The second part is the layout of the Banner itself.
I used for ad size SMART_BANNER. SMART_BANNER resizes automatically between phone and tablet size.
There are more sizes available. For more info go to Google Developer.
It is also necessary to add code to the Activity that calls this layout.
At last the AndroidManifest.xml needs som code, and configuration.part is to
The first part is to add the required permissions
Second you need to include the AdActivity
All the code snipsels can be found at the Google Developer page I mentioned earlier.
Time to run the App and check if the impressions are showing.
Looks good. Our “Money Maker” is ready to go.
In the next tutorial, I will go through the steps how to deploying the app to Google’s Play Store.
See you soon.
And don’t forget to promote your App:
For example with your own download badge, automaticly made for you by Google.
It could look like this: