Skip to content

00. How To Use with PhoneGap Build

Raymond Xie edited this page Sep 29, 2015 · 14 revisions

According to PhoneGap Build official blog, they support official Cordova Plugin registry now. http://phonegap.com/blog/2014/12/09/phonegap-build-new-features/

According to the blog, plugin can be used by configuring the plugin in the config.xml (for every app build with phonegap build service, you need have a config.xml in your root folder)

In your config.xml:

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

See full config.xml: https://github.com/floatinghotpot/phonegap-admob-demo/blob/master/config.xml

Then you can call AdMob plugin in your javascript code (after deviceready event fired)

Your index.html:

<!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>

See the More Code

Build APP with PhoneGap Build

Put your code on github, add app in PhoneGap Build with source from github.

Here is a simple demo project for phonegap build (with index.html and config.xml): https://github.com/floatinghotpot/phonegap-admob-demo

Build and get your app package, if build pass.

PhoneGapBuild