PhoneGap Cordova Admob 插件不工作 [英] PhoneGap Cordova Admob plugin not working

查看:32
本文介绍了PhoneGap Cordova Admob 插件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这个 AdMob 插件(https://github.com/rajpara11/phonegap-plugins/tree/master/Android/AdMobPlugin) 在 Android 中投放 AdMob 广告.我没有收到任何广告,屏幕底部有一大块 (25%) 区域是白色的.我确实收到此错误CordovaLog(275): TypeError: 表达式 'window.plugins' [undefined] 的结果不是对象."在模拟器中运行时在我的 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(),并调用 showBannerFunc() 和 showInterstitialFunc() 来展示广告.

-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆