Monetise your Android app | Admob integration | with code...

Making an Android app is one thing but earning from it is other. There are many ways to earn from apps like premium packs, subscription, buying stuff, ads. 
The advertisement would be the most efficient one and will give you good revenue. There are many advertising networks but Google provides AdMob which is more preferable in terms of standard and revenue too.

Also, read: Converting HTML5 Game for Android | 2 Methods


So let us start to code. I'll explain two types of ads only if you want me to explain the other two, comment for the same.

Steps to integrate AdMob into your Android app:

1. Creating an Admob account

  • Go to AdMob site sign in with your Google account.
  • Create an app and note down the App Id, which we'll use in our app to authenticate.


2. Import Mobile Ads' SDK

  • Open your gradle files and in your project-level gradle, put the below code, inside allprojects {} section.



3. Add Dependencies

  • Add the following in your app-level gradle.
  • The version may change you might want to check: Google Play Services





4. Update Manifest file

  • Add the following code to your manifest.xml, it includes metadata that'll authenticate your app with the AdMob app.


5. Initialize Mobile Ads

  • Add the Java code in your Acitivity.java file to initialize the Ad SDK.
  • Google encourages developers to use the sample app id for testing purposes, hence use the sample id.


6. Choose Ad Format

  • There are 4 ad formats provided by Google. For an app that includes a single page of multiple user interactions than I'll suggest going for Banner ad which appears at the bottom and will not distract the user.


Implementing Banner ad:

 Before moving forward, go to the AdMob account, click AdUnit add one Banner ad, note down the Ad Id.


 a. Add AdView to the layout file

  • This will add the ad to the activity layout, you don't need to make changes here since Google will manage the resource formatting. Also, sizes can differ, follow the page for sizes: Banner Sizes


 b. Or create AdView using Java code

  • Simple process, but recommend using the XML style.


 c. Load an Ad

  • Use the following code to initialize the AdView and assign money-making ads.


 d. Ad Events (Optional)

  • Use some events for customizing ads on your device.




Implement an Interstitial ad:

  Before moving forward, go to the AdMob account, click AdUnit add one Interstitial ad, note down the Ad Id.

 a. Create an object of the Interstitial ad:

 b. Load an Ad:


 c. Show the Ad:

 d.  Ad Events for reloading


Source Code:

  • Sample Interstitial app on GitHub
  • Sample Banner app on GitHub


Video Tutorials

You can comment in the section below to let me know if something is wrong or some suggestions.

Popular posts from this blog

Audio de-noising using Python (Wavelets)

Using FFMPEG to trim your videos

Converting HTML5 Game for Android | 2 Methods