Admob 无法在 phonegap 和 android 中工作

Admob not working in phonegap and android

我正在尝试将广告添加到我的 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

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

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

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。