【发布时间】:2016-06-09 21:05:50
【问题描述】:
我在我的 HTML 页面上的 Body 标记中添加了以下脚本。不过,我希望在我的应用上只显示横幅广告,我在这个脚本上添加了我真正的 Admob 应用广告代码;我发现构建的 apk 在 Bluestack 上显示来自 Admob 的测试广告。我使用 Android Studio 构建应用程序,同时通过 CLI 生成 Cordova 文件。
以下是确切的脚本:
<script> // place our admob ad unit id here var admobid = {}; if( /(android)/i.test(navigator.userAgent) ) { admobid = { // for Android banner: 'ca-app-pub-7964685388872167/7227221134', //my real admobid interstitial: 'ca-app-pub-6869992474017983/7563979554' //admob test id }; } else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { admobid = { // for iOS banner: 'ca-app-pub-6869992474017983/4806197152', interstitial: 'ca-app-pub-6869992474017983/7563979554' }; } else { admobid = { // for Windows Phone banner: 'ca-app-pub-6869992474017983/8878394753', interstitial: 'ca-app-pub-6869992474017983/1355127956' }; } function createSelectedBanner(){ if(AdMob) AdMob.createBanner({ adId: admobid.banner, overlap: $('#overlap').is(':checked'), offsetTopBar: $('#offsetTopBar').is(':checked'), adSize: $('#adSize').val(), position: $('#adPosition').val(), }); } function showBannerAtPosition(){ if(AdMob) AdMob.showBanner( $('#adPosition').val() ); } function onDeviceReady() { if (! AdMob) { alert( 'admob plugin not ready' ); return; } initAd(); // display a banner at startup createSelectedBanner(); } function initAd(){ AdMob.setOptions({ // adSize: 'SMART_BANNER', // width: integer, // valid when set adSize 'CUSTOM' // height: integer, // valid when set adSize 'CUSTOM' position: AdMob.AD_POSITION.BOTTOM_CENTER, // offsetTopBar: false, // avoid overlapped by status bar, for iOS7+ bgColor: 'black', // color name, or '#RRGGBB' // x: integer, // valid when set position to 0 / POS_XY // y: integer, // valid when set position to 0 / POS_XY isTesting: true, // set to true, to receiving test ad for testing purpose // autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show }); // new events, with variable to differentiate: adNetwork, adType, adEvent $(document).on('onAdFailLoad', function(e){ // when jquery used, it will hijack the event, so we have to get data from original event if(typeof e.originalEvent !== 'undefined') e = e.originalEvent; var data = e.detail || e.data || e; alert('error: ' + data.error + ', reason: ' + data.reason + ', adNetwork:' + data.adNetwork + ', adType:' + data.adType + ', adEvent:' + data.adEvent); // adType: 'banner', 'interstitial', etc. }); $(document).on('onAdLoaded', function(e){ }); $(document).on('onAdPresent', function(e){ }); $(document).on('onAdLeaveApp', function(e){ }); $(document).on('onAdDismiss', function(e){ }); $('#btn_create').click(createSelectedBanner); $('#btn_remove').click(function(){ AdMob.removeBanner(); }); $('#btn_show').click(showBannerAtPosition); $('#btn_hide').click(function(){ AdMob.hideBanner(); }); // create a banner on startup createSelectedBanner(); // test interstitial ad $('#btn_prepare').click(function(){ AdMob.prepareInterstitial({ adId:admobid.interstitial, autoShow: $('#autoshow').is(':checked'), }); }); $('#btn_showfull').click(function(){ AdMob.showInterstitial(); }); // test case for #256, https://github.com/floatinghotpot/cordova-admob-pro/issues/256 $(document).on('backbutton', function(){ if(window.confirm('Are you sure to quit?')) navigator.app.exitApp(); }); // test case #283, https://github.com/floatinghotpot/cordova-admob-pro/issues/283 $(document).on('resume', function(){ AdMob.showInterstitial(); }); } // test the webview resized properly $(window).resize(function(){ $('#textinfo').html('web view: ' + $(window).width() + " x " + $(window).height()); }); $(document).ready(function(){ // on mobile device, we must wait the 'deviceready' event fired by cordova if(/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent)) { document.addEventListener('deviceready', onDeviceReady, false); } else { onDeviceReady(); } }); </script>
所以 1:你能帮我解决这个问题吗?如何在我的应用上显示来自 Admob 的真实广告,而不是来自 admob 的测试广告?
2:如何在保持横幅代码不变的情况下从此脚本中删除 Irrestritial 和其他类型的广告代码?
谢谢。
【问题讨论】: