PhoneGap Cordova Admob plugin not working

2019-05-11 16:10发布

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.

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?

Thanks in advance

标签: cordova admob
3条回答
ゆ 、 Hurt°
2楼-- · 2019-05-11 16:44

Make sure you have added references to Phonegap/Cordova prior references to the AdMob plug-in, as it depends on it.

You can take a look at this video tutorial how to use PhoneGap plug-ins: http://www.youtube.com/watch?v=84jmuXS8GJI

Good luck!

查看更多
走好不送
3楼-- · 2019-05-11 16:44

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

Integration is as follows:

-Add the following javascript functions, put in your own ad code, play with the variables if you want.

-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();
}
查看更多
放荡不羁爱自由
4楼-- · 2019-05-11 16:48

Fixed it by commenting out this line in the code:

isTesting:true

查看更多
登录 后发表回答