我正在使用此AdMob插件(https://github.com/rajpara11/phonegap-plugins/tree/master/Android/AdMobPlugin)在Android中投放AdMob广告。我没有收到任何广告,底部有一个很大的(25%)屏幕区域是白色的。我收到此错误“CordovaLog(275):TypeError:表达式结果'window.plugins'[undefined]不是对象。”在模拟器中运行时,在我的Aptana / Eclipse日志中。
文档设置说要将“AdMob Cordova插件jar放在libs /中”。只有一个.Java文件。我应该将其编译成JAR文件并将其放在该文件夹中吗?是否有任何教程显示此插件有效?
提前致谢
答案 0 :(得分:0)
确保您已添加对Phonegap / Cordova之前对AdMob插件的引用的引用,因为它取决于它。
您可以查看此视频教程如何使用PhoneGap插件:http://www.youtube.com/watch?v=84jmuXS8GJI
祝你好运!答案 1 :(得分:0)
通过在代码中注释掉这一行来修正它:
isTesting:true
答案 2 :(得分:0)
尝试使用其他插件,因为听起来此插件已损坏。我知道这个有用
https://github.com/sunnycupertino/cordova-plugin-admob-simple
cordova plugin add cordova-plugin-admob-simple
整合如下:
- 添加以下javascript函数,输入您自己的广告代码,根据需要使用变量。
从onDeviceReady()调用initAd(),并使用showBannerFunc()和showInterstitialFunc()来显示广告。
//initialize the goodies
function initAd(){
if ( window.plugins && window.plugins.AdMob ) {
var ad_units = {
ios : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE
},
android : {
banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE
interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE
}
};
var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;
window.plugins.AdMob.setOptions( {
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER, //use SMART_BANNER, BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
bannerAtTop: false, // set to true, to put banner at top
overlap: true, // banner will overlap webview
offsetTopBar: false, // set to true to avoid ios7 status bar overlap
isTesting: false, // receiving test ad
autoShow: false // auto show interstitial ad when loaded
});
registerAdEvents();
window.plugins.AdMob.createInterstitialView(); //get the interstitials ready to be shown
window.plugins.AdMob.requestInterstitialAd();
} else {
//alert( 'admob plugin not ready' );
}
}
//functions to allow you to know when ads are shown, etc.
function registerAdEvents() {
document.addEventListener('onReceiveAd', function(){});
document.addEventListener('onFailedToReceiveAd', function(data){});
document.addEventListener('onPresentAd', function(){});
document.addEventListener('onDismissAd', function(){ });
document.addEventListener('onLeaveToAd', function(){ });
document.addEventListener('onReceiveInterstitialAd', function(){ });
document.addEventListener('onPresentInterstitialAd', function(){ });
document.addEventListener('onDismissInterstitialAd', function(){
window.plugins.AdMob.createInterstitialView(); //REMOVE THESE 2 LINES IF USING AUTOSHOW
window.plugins.AdMob.requestInterstitialAd(); //get the next one ready only after the current one is closed
});
}
//display the banner
function showBannerFunc(){
window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
window.plugins.AdMob.showInterstitialAd();
}