PhoneGap Cordova Admob插件无法工作

3
我正在使用这个AdMob插件(https://github.com/rajpara11/phonegap-plugins/tree/master/Android/AdMobPlugin)在Android中提供AdMob广告服务。但我没有得到任何广告,屏幕底部有一个大的(25%)白色区域。当在模拟器中运行时,我的Aptana / Eclipse日志中出现了“CordovaLog(275):TypeError:表达式'result of expression 'window.plugins' [undefined] is not an object.”的错误。
文档设置说要将“AdMob Cordova插件jar放入libs /”中。但是只有一个.java文件。我应该将其编译成JAR文件并将其放入该文件夹吗?是否有任何展示此插件工作的教程?
提前感谢。
3个回答

0

在引用AdMob插件之前,请确保您已经添加了Phonegap/Cordova的引用,因为它依赖于它。

您可以观看这个视频教程,了解如何使用PhoneGap插件:http://www.youtube.com/watch?v=84jmuXS8GJI

祝你好运!


0

通过在代码中注释掉这行代码来解决问题:

isTesting:true


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();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接