【问题标题】:InterstitialAds are not loading in activity while loading every 90 seconds每 90 秒加载一次,插页式广告未加载到活动中
【发布时间】:2019-04-16 11:10:23
【问题描述】:
private final String TAG = "RedFM_AdsDemoActivity";
    private InterstitialAd interstitialListen;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ads_demo);
    MobileAds.initialize(this, getString(R.string.google_ad_app_id));
    // Create the InterstitialAd and set the adUnitId.
    interstitialListen = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    interstitialListen.setAdUnitId(getString(R.string.admob_interstitial_id_google));
    interstitialListen.loadAd(new AdRequest.Builder().build());
    interstitialListen.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {              
            loadInterstitial();
        }
    });
    resumeGame(20000);
}

private static final long GAME_LENGTH_MILLISECONDS = 20000;
public CountDownTimer countDownTimer;
public boolean gameIsInProgress;

public void createTimer(final long milliseconds) {
    // Create the game timer, which counts down to the end of the level
    // and shows the "retry" button.
    if (countDownTimer != null) {
        countDownTimer.cancel();
    }
    countDownTimer = new CountDownTimer(milliseconds, 1000) {
        @Override
        public void onTick(long millisUnitFinished) {

        }

        @Override
        public void onFinish() {
            gameIsInProgress = false;
            showInterstitial();
        }
    };
}

public void showInterstitial() {
    // Show the ad if it's ready. Otherwise toast and restart the game.
    if (interstitialListen != null && interstitialListen.isLoaded()) {
        interstitialListen.show();         
    } else {
        loadInterstitial();
    }
}

public void loadInterstitial() {
    // Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
    if (!interstitialListen.isLoading() && !interstitialListen.isLoaded()) {
        System.out.println(TAG + "Listen  ads loaded");
        AdRequest adRequest = new AdRequest.Builder().build();
        interstitialListen.loadAd(adRequest);
    } else
        System.out.println(TAG + "Listen  ads not loaded");
    resumeGame(GAME_LENGTH_MILLISECONDS);
}

public void resumeGame(long milliseconds) {
    // Create a new timer for the correct length and start it.
    System.out.println(TAG + "Listen  resumeGame called ");
    gameIsInProgress = true;
    createTimer(milliseconds);
    countDownTimer.start();
}

@Override
protected void onPause() {
    super.onPause();
    if (countDownTimer != null)
        countDownTimer.cancel();
}

**1.当我将 ListenActivity 移动到 MainActivity 时,当时两个 Activity 上都加载了广告。

但是当我将 MainActivity 移动到 ListenActivity 时,此时广告在 MainActivity 上显示,但在 ListenActivity 上未加载广告。我收到“广告无法加载:0”请帮助我在来自 MainActivity 时在 ListenActivity 上显示广告。* *

【问题讨论】:

    标签: java android gadinterstitial


    【解决方案1】:

    使用Test Ad Idsdebug 应用中展示广告。 Ad-mob new SDK 不要在debug 模式下显示ads 或发布APK 然后会显示广告。

    【讨论】:

    • 使用 ca-app-pub-3940256099942544/1033173712 加载广告(由谷歌提供用于测试广告),实际上它在主要活动中工作,但是当我导航到另一个活动时它不会加载
    • 您是否尝试为回调添加侦听器。它在 onFailed() 方法中给出的错误代码。如果它是“3”,那么不要担心一切正常。添加当前未加载。对于其他错误代码,您可以查看 admob 文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多