android 如何使用Google移动的Ads SDK版本20.0.0检查插播广告是否正在加载

6ojccjat  于 2023-06-27  发布在  Android
关注(0)|答案(2)|浏览(227)
  • 对于20.0.0之前的SDK版本,我们可以检查Interstitial是否正在加载以下代码:
private InterstitialAd mInterstitialAd;
mInterstitialAd.isLoading();
  • 对于SDK版本20.0.0,我们只能检查Interstitial是否加载了以下代码:
InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
      new InterstitialAdLoadCallback() {
    @Override
    public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
      mInterstitialAd = interstitialAd;
      Log.i(TAG, "onAdLoaded");
    }
  });

SDK版本20.0.0中是否有方法检查是否正在加载插播广告?

mrfwxfqh

mrfwxfqh1#

似乎没有内置的方法来做到这一点,但你可以很容易地做到:

private boolean isLoaded = false;
private void loadAd(){
   InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
       new InterstitialAdLoadCallback() {
          @Override
          public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
             mInterstitialAd = interstitialAd;
             isLoaded = true;
             Log.i(TAG, "onAdLoaded");
          }
       });
}

然后简单地得到isLoaded的值。

axr492tv

axr492tv2#

private boolean isLoaded = false;
private void loadAd(){
isLoaded = false;
InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
   new InterstitialAdLoadCallback() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
         mInterstitialAd = interstitialAd;
         isLoaded = true;
         Log.i(TAG, "onAdLoaded");
      }
      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
      isLoaded = false;
      Log.i(TAG, "Loading ad failed");
      }
   });

}

相关问题