1

我试图在我的 android phonegap 应用程序中添加广告,但我没有得到任何东西......我使用 phonegap 0.3.3

我的 admob 键广告键是这样的:ca-app-pub-9718633180389415/1973821888

我的 config.xml 我有:

<plugin name="com.admob.google" spec="4.0.8" source="pgb" />

然后尝试了我的索引:

function onDeviceReady() {
      document.removeEventListener('deviceready', onDeviceReady, false);

      // Set AdMobAds options:
      admob.setOptions({
        publisherId:          "ca-app-pub-9718633180389415/1973821888",  // Required
        interstitialAdId:     "ca-app-pub-9718633180389415/1973821888",  // Optional
        tappxIdiOs:           "/XXXXXXXXX/Pub-XXXX-iOS-IIII",            // Optional
        tappxIdAndroid:       "/XXXXXXXXX/Pub-XXXX-Android-AAAA",        // Optional
        tappxShare:           0.5                                        // Optional
      });

      // Start showing banners (atomatic when autoShowBanner is set to true)
      admob.createBannerView();

      // Request interstitial (will present automatically when autoShowInterstitial is set to true)
      admob.requestInterstitial();
    }

但会显示:我正在使用https://github.com/sunnycupertino/cordova-plugin-admob-simple

4

2 回答 2

2

cordova-admob插件的作者在这里。你试过isTesting: true吗?你是在真机上运行吗?请注意,它不适用于浏览器(仅限模拟器或真实设备)。

在你的config.xml

<gap:plugin name="phonegap-admob" source="npm"/>

在您的 javascript 中:

function onDeviceReady() {
  document.removeEventListener('deviceready', onDeviceReady, false);

  // Set AdMobAds options:
  admob.setOptions({
    publisherId:          "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",  // Required
    interstitialAdId:     "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",  // Optional
    isTesting:            true  // Optional
  });

  // Start showing banners (atomatic when autoShowBanner is set to true)
  admob.createBannerView();

  // Request interstitial (will present automatically when autoShowInterstitial is set to true)
  admob.requestInterstitialAd();
}

document.addEventListener("deviceready", onDeviceReady, false);

在此处查看更多详细信息:https ://github.com/appfeel/admob-google-cordova/wiki/Setup

于 2016-06-28T15:02:30.813 回答
-1

不确定这是否有用,但我以为我使用的是与您相同的插件,实际上,我使用的是这个插件:

https://github.com/admob-google/admob-cordova

为了使用该插件,我编写了以下代码:

var AdmobManager = {
    // admob configuration
    admobCfg: {},

    // Initialize admob support, and start showing a banner right away
    initAdmob: function () {
        // If we don't have admob support, don't try to configure anything
        if (!admob) 
            return;

        // Configure the IDs for the iOS and Android banner and interstitial ads
        AdmobManager.admobCfg.iosCfg = {
            banner: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
            interstitial: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
        };
        AdmobManager.admobCfg.androidCfg = {
            banner: "ca-app-pub-XXXXXXXXXXXXXXXX/RRRRRRRRRR",
            interstitial: "ca-app-pub-XXXXXXXXXXXXXXXX/HHHHHHHHHH"
        };

        // Choose ad IDs based on platform
        AdmobManager.admobCfg.activeCfg = (/(android)/i.test(navigator.userAgent)) ? AdmobManager.admobCfg.androidCfg : AdmobManager.admobCfg.iosCfg;

        // Now we can init admob: set the IDs, and build a param for testing mode
        admob.initAdmob(AdmobManager.admobCfg.activeCfg.banner, AdmobManager.admobCfg.activeCfg.interstitial);
        AdmobManager.admobCfg.extraParams = new admob.Params();
        AdmobManager.admobCfg.extraParams.isTesting = true;

        // Request banner ads immediately upon app start
        admob.showBanner(admob.BannerSize.BANNER, admob.Position.BOTTOM_CENTER, AdmobManager.admobCfg.extraParams);
    },

    // start allowing Admob interstitials
    enableAdmobInterstitial: function () {
        // If we don't have admob support, don't try to configure anything
        if (!admob) 
            return;

        // Set up a listener for showing an interstitial once it arrives
        document.addEventListener(admob.Event.onInterstitialReceive, function (message) {
            admob.showInterstitial();
        }, false);

        // Request an interstitial to be sent
        admob.cacheInterstitial(AdmobManager.admobCfg.extraParams);
    }
}

我什至在显示登录屏幕之前调用AdmobManager.initAdmob(),然后在登录后调用AdmobManager.enableAdmobInterstitial().

当然,一旦你完成了测试,你会想要更改isTesting为 false。

于 2016-06-28T19:34:44.280 回答