Admob Native Android SDK Integration with Phonegap/Cordova without Plugins – Code Theory

2 min


Just like we’ve Google’s AdSense program for all net publishers to generate income off their content material, for cellular app builders there’s Google’s AdMob advertisements platform to monetize and promote their net app. PhoneGap is a good software to transform JavaScript wealthy net apps to native cellular app. But in relation to monetizing by way of advertisements, simply placing Adsense code is just not the answer as its meant for net utilization solely and is in opposition to Google’s phrases and situations. We’ll undergo a easy course of that I got here throughout to combine the native admob android sdk to our cordova apps and video games without utilizing any phonegap plugins.

Let’s simply comply with these few steps.

What’s the one factor each developer needs? More screens! Enhance your coding expertise with an exterior monitor to extend display screen actual property.

Install the Native Android SDK

Download the Android Admob SDK, extract it and replica GoogleAdMobAdsSdk-*.*.*.jar to the PhoneGap venture’s libs listing.

Recommended for you:

Now refresh your venture listing in Eclipse and add the newly downloaded SDK’s jar file to the venture’s construct path. You can do that by following these easy steps:

Include Admob’s Library

Add the next strains in your proper under different imports.

Here, the primary import comprises the capabilities associated to advertisements whereas the second will assist us in inserting the advertisements into the display screen.

Configure your AdMob advert unit ID

Now, inside the principle class of your file, create a brand new non-public string AdMob_Ad_Unit like this:

Make certain to interchange xxxxxxxxxxxxxxx with your individual ID as placing incorrect ID there’ll end in no advertisements displaying up. Now we’re prepared to indicate the advertisements in our app!

Create the Ad View

Below the newly added string, add yet another non-public variable advertView of AdView sort like this:

This would be the container for the advert. Now, contained in the onCreate operate, add the next strains on the backside:

This ought to be sufficient for the advertisements to indicate up in an actual system. However, if you wish to take a look at the advertisements on a Android Virtual Machine, you then’ll have so as to add this line above advertView.loadAd(request); and advertisements will begin displaying up within the AVDs.

Make certain to remark out the above added line earlier than publishing the app for apparent causes!

So all the code file ought to appear like this:

Final Steps

The final step is to outline the newly created Ads exercise into the AndroidManifest.xml file. Add this line in your manifest file after the closing tag of your foremost exercise.

Now you will need to be capable to see the advertisements when operating the app in an emulator or on an actual system. If you run into an issue or doesn’t get it to work then drop us a remark right here and we’ll show you how to! 🙂

Recommended from our customers: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch.

Rishabh is a full stack net and cellular developer from India. Follow me on Twitter.
View all posts by Rishabh

What's Your Reaction?

hate hate
confused confused
fail fail
fun fun
geeky geeky
love love
lol lol
omg omg
win win


Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Voting to make decisions or determine opinions
Formatted Text with Embeds and Visuals
The Classic Internet Listicles
Upload your own images to make custom memes
Youtube, Vimeo or Vine Embeds
Soundcloud or Mixcloud Embeds
Photo or GIF
GIF format