Tom
Tom

Reputation: 654

Google Play Admob integration with Phonegap

How do you add Google Admob to a phonegap app (android) in 2014?

I have checked many examples online e.g. link1 link2 Link3 Link4. Most link to Googles soon to be deprecated Android 6.4.1 tutorial.

Apart from specific android or iOS tutorials, I cannot find any that demonstrate how to implement the latest admob into phonegap for a cross platform app. I have seen inmobi however it looks like you have to publish your app before you can get a publisher id for your adverts.

Update with Android simplified instructions I am getting the black box for the advert however nothing else, no alert messages, no advert

phonegap create myproject
cd mypproject
phonegap run android

Close down the emulator

1.Install the Google Play Services plugin:  cordova plugin add     https://github.com/MobileChromeApps/google-play-services.git  
2.Install this plugin:  cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob.git  

Then I headed over to index.js and onDeviceReady I added

   onDeviceReady: function() {
     app.receivedEvent('deviceready');

if( window.plugins && window.plugins.AdMob ) {
    var admob_android_key = 'pub-6xxxxxxxxxxxxx';
    var am = window.plugins.AdMob;

    am.createBannerView( 
    {
    'publisherId': admob_android_key,
    'adSize': am.AD_SIZE.BANNER,
    'bannerAtTop': true
    }, 
    function() {
        am.requestAd(
            { 'isTesting':true }, 
            function(){
                am.showAd( true );
            }, 
            function(){ alert('failed to request ad'); }
        );
    }, 
    function(){ alert('failed to create banner view'); }
    );
    } else {
    alert('AdMob plugin not available/ready.');
    }

  }

Added to index.html

       <div>
            <button id='show-ad' onClick="if(window.plugins.AdMob){ window.AdMob.plugins.showAd(true); }">Show Ad</button>
            <button id='hide-ad' onClick="if(window.plugins.AdMob){ window.AdMob.plugins.showAd(false); }">Hide Ad</button>
        </div>

phonegap run android

Upvotes: 13

Views: 11159

Answers (3)

Miquel
Miquel

Reputation: 8989

Review (2016). In order to use it with npm sources, if you are using cordova CLI version, you can add your plugin with:

$ cordova plugin add cordova-admob

If you are integrating with phonegap build, as they don't support gradle (at this moment), you should add this tag in your config.xml:

<gap:plugin name="phonegap-admob" source="npm"/>

There are full set-up instructions and wiki here

Upvotes: 3

Prithvi Raj Nandiwal
Prithvi Raj Nandiwal

Reputation: 3294

Here is a blog. So that you can ad admob in your Phonegap app without any plugin. http://phonegapguru.blogspot.in/2014/11/how-to-add-native-admob-ad-in.html?m=1

Upvotes: 0

DonAngelo
DonAngelo

Reputation: 106

This admob plugin works with google play sdk: https://github.com/floatinghotpot/cordova-plugin-admob . Check readmes in main folder AND in subfolders for details.

Upvotes: 9

Related Questions