-
Notifications
You must be signed in to change notification settings - Fork 338
00. How To Use with PhoneGap Build
According to Cordova team announcement, the cordova registry is deprecated, and all plugins are moved to npm, and renamed as "cordova-plugin-xxx".
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" />
Be aware that, there is some slight difference between the two plugins:
-
cordova-plugin-admobpro
,<framework src="com.google.android.gms:play-services-ads:+" />
, it requires gradle to build android apk, but so far PhoneGap Build does not support it yet and still use ant. -
cordova-plugin-admob
,<dependency id="cordova-plugin-googleplayservices"/>
, it depends on a plugin contains google-play-services.jar
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
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.