我使用PhoneGap 3.4进行Android应用程序构建。
我正在运行的插件是:https://github.com/floatinghotpot/cordova-plugin-admob.git
安装说明如下:
A simplified method (tested on Cordova 3.4.0)
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```
展示广告的说明是:
##Using the Plugin:
There are 3 calls needed to get AdMob Ads:
1. `createBannerView`
Takes in a object containing a publisherId and adSize, as well as success
and failure callbacks. An example call is provided below:
window.plugins.AdMob.createBannerView(
{
'publisherId': 'INSERT_YOUR_PUBLISHER_ID_HERE',
'adSize': window.plugins.AdMob.AD_SIZE.BANNER
},
successCallback,
failureCallback
);
2. `requestAd`
Takes in an object containing an optional testing flag, and an optional
list of extras. This method should only be invoked once createBannerView
has invoked successCallback. An example call is provided below:
window.plugins.AdMob.requestAd(
{
'isTesting': false,
'extras': {
'color_bg': 'AAAAFF',
'color_bg_top': 'FFFFFF',
'color_border': 'FFFFFF',
'color_link': '000080',
'color_text': '808080',
'color_url': '008000'
},
},
successCallback,
failureCallback
);
3. `showAd`
Show or hide the Ad.
只有在createBannerView调用successCallback后才能调用此方法 下面提供了一个示例调用: window.plugins.AdMob.showAd( 真正, successCallback, failureCallback ); 这是我的尝试:
function onLoad(){
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
if(window.plugins && window.plugins.AdMob) {
var admob_android_key = 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxx';
var adId = (navigator.userAgent.indexOf('Android') >=0) ? admob_android_key : admob_ios_key;
var am = window.plugins.Admob;
am.createBannerView(
{
'publisherId': adId,
'adSize': am.AD_SIZE.BANNER,
'bannerAtTop': false
},
function() {
am.requestAd(
{ 'isTesting':false },
function(){
am.showAd( true );
},
function(){ alert('failed to request ad'); }
);
},
function(){ alert('failed to create banner view'); }
);
} else {
alert('AdMob plugin not available/ready.');
}
}
知道我哪里错了吗?提前谢谢。
答案 0 :(得分:0)
你粘贴的东西太复杂了
有几个展示广告的权利。 1.install,只需在phonegap build config中添加它
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>
2.config admob
admob.showBannerAbsolute(admob.BannerSize.BANNER,0,70);
3.显示你想要的广告。
admob.showBanner(admob.BannerSize.BANNER,admob.Position.TOP_APP);
就是这样。