【问题标题】:PhoneGap Cordova Admob plugin not workingPhoneGap Cordova Admob 插件不工作
【发布时间】:2013-03-19 03:02:07
【问题描述】:

我正在使用这个 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 文件并将其放在该文件夹中?是否有任何教程显示此插件的工作原理?

提前致谢

【问题讨论】:

    标签: cordova admob


    【解决方案1】:

    确保您在引用 AdMob 插件之前添加了对 Phonegap/Cordova 的引用,因为它取决于它。

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

    祝你好运!

    【讨论】:

      【解决方案2】:

      通过在代码中注释掉这一行来修复它:

      isTesting:true

      【讨论】:

        【解决方案3】:

        尝试不同的插件,因为听起来这个插件坏了。我知道这个有效

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-26
          • 1970-01-01
          • 2014-02-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多