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

2 min


0

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 MainActivity.java 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 MainActivity.java 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
0
hate
confused confused
0
confused
fail fail
0
fail
fun fun
0
fun
geeky geeky
0
geeky
love love
0
love
lol lol
0
lol
omg omg
0
omg
win win
0
win

0 Comments

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
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Meme
Upload your own images to make custom memes
Video
Youtube, Vimeo or Vine Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format