【问题标题】:Ads are not showing but Why?广告没有显示,但为什么?
【发布时间】:2014-08-27 15:29:28
【问题描述】:

我正在使用 phonegap 开发一个 android 应用程序。我已经成功添加了 google-play-services 库项目。现在我想整合 AdMob 用于广告目的。我已经按照这些步骤https://developers.google.com/mobile-ads-sdk/docs/。我的项目已成功构建并运行,但那里没有显示广告。

我在 index.html 中添加了 AdMob Cordova 插件和 SCRIPT。这是我的 index.html

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!--<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />-->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
        <!--<link rel="stylesheet" type="text/css" href="css/index.css" />-->
        <!-- <link href="lib/ionic/css/ionic.css" rel="stylesheet"> -->
        <link href="css/app.css" rel="stylesheet">
        <!-- <link href="css/leaflet.css" rel="stylesheet">
        <link href="css/leaflet.draw.css" rel="stylesheet">
        <link href="css/nv.d3.css" rel="stylesheet"> -->
        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->
        <style type="text/css">
          .css-form input.ng-invalid.ng-dirty {
            /*background-color: #FA787E;*/
              outline: none;
              box-shadow:0px 0px 7px #FA787E;
              border-color:#FA787E;
          }

          .css-form input.ng-valid.ng-dirty {
            /*background-color: #78FA89;*/
              outline: none;
              box-shadow:0px 0px 7px #78FA89;
              border-color:#78FA89;
          }


        </style>
        <!-- ionic/angularjs js -->
        <script src="js/leaflet.js"></script>
        <script src="js/d3.js"></script>
        <script src="js/nv.d3.js"></script>
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="js/ng-cordova.js"></script>
        <script src="js/geolocation.js"></script>

        <script src="js/angularjs-nvd3-directives.js"></script>
        <script src="js/angular-cookies.js"></script>

        <script src="js/angular-resource.js"></script>
        <script src="js/angular-leaflet-directive.min.js"></script>
        <script src="js/leaflet.draw.js"></script>

    </head>
    <body ng-app="starter">
            <ion-nav-view animation="slide-left-right-ios7">
            </ion-nav-view>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="deviceinfo.js"></script>
        <script type="text/javascript" src="telephonenumber.js"></script>
        <script type="text/javascript" src="sharedprefs.js"></script>
        <!-- your app's js -->
        <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script src="js/services.js"></script>
        <script src="js/controllers.js"></script>
        <script src="js/app.js"></script>
        <script type="text/javascript" src="js/geolib.js"></script>
        <script type="text/javascript" src="js/moment.min.js"></script>
        <script type="text/javascript">
        Date.prototype.deductHours= function(h){
            this.setHours(this.getHours()-h);
            return this;
        }
        Date.prototype.addHours= function(h){
            this.setHours(this.getHours()+h);
            return this;
        }
    </script>
    <script>
        function onDocLoad() {
                    initApp();                    
        }

        function initApp() {
            initAd();

        console.log("initApp is running");
            // display the banner at startup
            window.plugins.AdMob.createBannerView();
        }
        function initAd(){
            if ( window.plugins && window.plugins.AdMob ) {
                console.log("initAd is running");
                var ad_units = {
                    ios : {
                        banner: 'ca-app-pub-2899535788334936/6458250207',
                        interstitial: 'ca-app-pub-2899535788334936/3672907408'
                    },
                    android : {
                        banner: 'ca-app-pub-2899535788334936/6458250207',
                        interstitial: 'ca-app-pub-2899535788334936/3672907408'
                    }
                };
                var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;

                window.plugins.AdMob.setOptions( {
                    publisherId: admobid.banner,
                    interstitialAdId: admobid.interstitial,
                    bannerAtTop: false, // set to true, to put banner at top
                    overlap: false, // set to true, to allow banner overlap webview
                    offsetTopBar: false, // set to true to avoid ios7 status bar overlap
                    isTesting: false, // receiving test ad
                    autoShow: true // auto show interstitial ad when loaded
                });

                registerAdEvents();

            } else {
                alert( 'admob plugin not ready' );
            }
        }
       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(){ });
        }
        function onResize() {
            var msg = 'web view: ' + window.innerWidth + ' x ' + window.innerHeight;
            document.getElementById('sizeinfo').innerHTML = msg;
        }
        </script>
    </body>
</html>

谁能告诉我我在这里错过了什么?我认为我的项目无论如何都找不到插件。但我也在 config.xml 中添加了插件。那怎么了?请回复!!

【问题讨论】:

    标签: android cordova admob phonegap-plugins


    【解决方案1】:

    无需为GCM and AdMob 添加单独的sdk,google play services 包含两个sdk 你可以使用它。使用包含两个 sdk 包的最新 android google play services

    【讨论】:

    • 感谢您的回答。实际上我已经配置了 google-play-services 库项目,然后在没有 Admob SDK 的情况下添加了 Admob 插件(我的项目正在 PhoneGap 上开发)。 GCM 运行良好,但 admob 插件不工作。 LogCat 没有为 AdMob 显示任何内容。我实际上正在关注这个github.com/floatinghotpot/cordova-plugin-admob。我还在 config.xml 中添加了
    • 我正在关注 github.com/floatinghotpot/cordova-plugin-admob 这个但我没有将 admob jar 导入我的项目(我已删除 来自 pluin.xml)。我正在使用 AdMob.java 和 AdMob.js 并在 index.html 中添加所需的脚本。
    • Google 已经用所有的 sdk 更新了google play services lib,所以你必须为所有与 google 相关的 sdk 使用这个。如果它解决了您的问题,请将其作为答案。
    • 正如我在之前的评论中提到的,我已经添加了 google-play-services。所以我现在没有使用任何其他库。我的项目已通过 google-play-services 构建并正常运行。我认为我的插件调用不正确。
    【解决方案2】:

    您正在使用旧方式,实际上,谷歌已经宣布更新 google_play_services 库,其中包含您所有的个人库。所以不要使用单独的库,只需更新 google_play_service 库并继续...!!!

    【讨论】:

      【解决方案3】:

      好的,我的问题解决了。该问题与 google-play-services 配置无关。所以我不能接受任何答案。谢谢大家帮助我。至少我确信我在 google-play-servicesadmob 配置中没有错。

      【讨论】:

      • 出了什么问题?
      猜你喜欢
      • 1970-01-01
      • 2015-11-13
      • 2022-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      相关资源
      最近更新 更多