Google’s AdSense program for all web publishers to generate revenue off their content, for mobile app developers there’s Google’s AdMob ads platform to monetize and promote their web app. PhoneGap is a great tool to convert JavaScript rich web apps to native mobile app .i’ll go through a simple process that I came across to integrate the native admob android sdk to your Phonegap/Cordova apps

Admob Native Android SDK Integration

Now you need just follow these few steps:

Install the Admob Android SDKDownload the Android Admob SDK, extract it and copy GoogleAdMobAdsSdk-*.*.*.jar to the PhoneGap project’s libs directory.

project’s libs directory

Select the Project ‘File’ -> ‘Project Structure’ from the  Modules .
Now select  Source Tab  select the ‘+ Add Content Root’ Button and by opening windows Select Your  GoogleAdMobAdsSdk-*.*.*.jar file
Select yourProject/libs/GoogleAdMobAdsSdk-*.*.*.jar


Include Admob’s Library

 Add the following lines in your right below other imports.

import android.widget.LinearLayout;

 Here, the first import contains the functions related to ads while the second one will help us in inserting the ads into the screen.

Configure your AdMob ad unit ID

Now, inside the main class of your file, create a new private string AdMob_Ad_Unit like this:

private static final String AdMob_Ad_Unit = "xxxxxxxxxxxxxxx";

Make sure to replace xxxxxxxxxxxxxxx with your own ID as putting incorrect ID there will result in no ads showing up.

Create the Ad View

Below the newly added string, add one more private variable adView of AdView type like this:
private AdView adView;
This will be the container for the ad. Now, inside the onCreate function, add the following lines at the bottom:
adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit);
LinearLayout layout = super.root;
AdRequest request = new AdRequest();
This should be enough for the ads to show up in a real device. However, if you want to test the ads on a Android Virtual Machine, then you’ll have to add this line above adView.loadAd(request); and ads will start showing up in the AVDs.
Make sure to comment out the above added line before publishing the app for obvious reasons!
So the entire code file should look like this:

import android.os.Bundle;
import org.apache.cordova.*;
import android.widget.LinearLayout;

public class MainActivity extends DroidGap
private static final String AdMob_Ad_Unit = "xxxxxxxxxxxxxxx";
private AdView adView;

public void onCreate(Bundle savedInstanceState)

// Set by in config.xml

adView = new AdView(this, AdSize.BANNER, AdMob_Ad_Unit);
LinearLayout layout = super.root;
AdRequest request = new AdRequest();

// Comment this out before publishing.
// request.addTestDevice(AdRequest.TEST_EMULATOR);


Final Steps

The last step is to define the newly created Ads activity into the AndroidManifest.xml file. Add this line in your manifest file after the closing tag of your main activity.
Now you must be able to see the ads when running the app in an emulator or on a real device. If you run into a problem or doesn’t get it to work then drop a comment here and i will  help you! 

HTML5 Hybrid Apps with Admob* Cordova* plug-in

If you want to include AdMob advertisements as part of your HTML5 hybrid mobile app, you will need to use a Cordova plugin.
There are a variety of Cordova plugins available for serving ads; some serve ads from third-party sources. A few serve ads from the AdMob network.
For example, the Cordova plug-in provides the capability to initiate Banner and Interstitial ads as well as handle admob ad events.

how to install google admob using phonegap plugin

Flowing the steep see here

Previous articlehow to change android studio theme
Next articlehow to add Google Analytics Android Apps & Native Application

Abdullah Al Mahamud is a programmer and founder of Thedevline an Inspiration blog since 2014. live in Bangladesh. He is passionate about Technology and Design. He works on the freelancing marketplace as a freelancer and has also written for Useful Article in this blog

Leave a Reply

Notify of