PhoneGap Cordova Admob插件不起作用 [英] PhoneGap Cordova Admob plugin not working
问题描述
我正在使用此AdMob插件( https://github.com / rajpara11 / phonegap-plugins / tree / master / Android / AdMobPlugin )以在Android中投放AdMob广告。我没有收到任何广告,并且屏幕底部有一个很大的区域(25%)是白色的。我确实收到此错误 CordovaLog(275):TypeError:表达式 window.plugins的结果[未定义]不是对象。在模拟器中运行时,请在我的Aptana / Eclipse日志中查看。
I am using this AdMob plugin (https://github.com/rajpara11/phonegap-plugins/tree/master/Android/AdMobPlugin) to serve AdMob ads in Android. I am not getting any advertisements and there is a large (25%) area of the screen at the bottom that is white. I do get this error "CordovaLog(275): TypeError: Result of expression 'window.plugins' [undefined] is not an object." in my Aptana/Eclipse log when running in the emulator.
文档设置要求将 AdMob Cordova插件jar放在libs /中。只有一个.Java文件。我是否应该将其编译成一个JAR文件并将其放在该文件夹中?有没有显示该插件正常工作的教程?
The documentation setup says to put the "AdMob Cordova plugin jar inside libs/". There is only a .Java file. Am I supposed to compile this into a JAR file and put it in that folder? Are there any tutorials showing this plugin working?
预先感谢
推荐答案
尝试使用其他插件,因为听起来好像该插件已损坏。我知道这很有效
Try a different plugin as it sounds like this plugin is broken. I know this one works
https ://github.com/sunnycupertino/cordova-plugin-admob-simple
cordova plugin add cordova-plugin-admob-simple
集成如下:
-添加以下javascript函数,放入您自己的广告代码,并根据需要使用变量。
-Add the following javascript functions, put in your own ad code, play with the variables if you want.
-从onDeviceReady()调用initAd(),
-Call initAd() from onDeviceReady(), and showBannerFunc() and showInterstitialFunc() to show ads.
//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();
}
这篇关于PhoneGap Cordova Admob插件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!