Skip to content

01. How to Use with Cordova CLI

Raymond Xie edited this page Sep 30, 2015 · 2 revisions

Add the plugin to your cordova project with Cordova CLI:

Video Tutorial

Video Clip at Youtube:

Tools Required

You need have following tools installed:

Quick Steps

# cordova create <project_folder> com.<company_name>.<app_name> <AppName>
# cd <project_folder>
cordova create testadmob com.rjfun.testadmob TestAdMob
cd testadmob
cordova platform add android
cordova platform add ios

cordova plugin add cordova-plugin-admobpro

# copy the demo html file to www
rm -r www/*; 
cp plugins/cordova-plugin-admobpro/test/index.html www/

# connect device or run in emulator
cordova prepare; 
cordova run android; 
cordova run ios;

// or import into Xcode / eclipse

Example Code

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello</title>
<script type="text/javascript" src="cordova.js"></script>
</head>
<body>
<h1>Hello AdMob</h1>
</body>
<script>
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) { 
    admobid = { // for Android
        banner: 'ca-app-pub-6869992474017983/9375997553',
        interstitial: 'ca-app-pub-6869992474017983/1657046752'
    };
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
    admobid = { // for iOS
        banner: 'ca-app-pub-6869992474017983/4806197152',
        interstitial: 'ca-app-pub-6869992474017983/7563979554'
    };
} else {
    admobid = { // for Windows Phone
        banner: 'ca-app-pub-6869992474017983/8878394753',
        interstitial: 'ca-app-pub-6869992474017983/1355127956'
    };
}

function initApp() {
    if (AdMob) {
        AdMob.createBanner({
            adId : admobid.banner,
            position : AdMob.AD_POSITION.BOTTOM_CENTER,
            autoShow : true
        });
    }
}

document.addEventListener('deviceready', initApp, false);
</script>
</html>