【问题标题】:AdMob interstitial doesn't show on AndroidAdMob 插页式广告未在 Android 上显示
【发布时间】:2014-03-03 21:34:59
【问题描述】:

我有一个 Android 应用,我正在尝试向其中添加 AdMob 插页式广告。我是这样创建的

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(getResources().getString(R.string.ad));
interstitial.loadAd(AdUtils.createRequest());

在适当的时候,我会这样向他们展示:

if(interstitial.isLoaded()) {
    interstitial.show();
}

当我在模拟器上测试这段代码时,一切都很好。但是当我在真实设备上运行它时,它通常(大约一半的节目)只显示一个带有关闭按钮的黑屏,根本没有广告图像。这个问题有解决办法吗?

【问题讨论】:

  • 试试下面的代码,让我知道它是否有效。

标签: android admob


【解决方案1】:

你可以尝试如下。

将此声明为变量。

private InterstitialAd interstitial;

然后在你的 onCreate 方法中使用这部分

interstitial = new InterstitialAd(this, "your id");

// Create ad request
AdRequest adRequest = new AdRequest();  

// Begin loading your interstitial
interstitial.loadAd(adRequest);

// Set Ad Listener to use the callbacks below
interstitial.setAdListener(this);

最后将其设置在您的 onCreate 方法之外,因此基本上在您的活动中设置以下代码..

@Override
    public void onReceiveAd(Ad ad) {
        // TODO Auto-generated method stub
        if (ad == interstitial) {
              interstitial.show();
            }
    }

希望这会对你有所帮助。

【讨论】:

  • 谢谢,但我使用的是 Google Play 版本的 Mobile Ads SDK,与您的版本略有不同
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-16
  • 1970-01-01
相关资源
最近更新 更多