【问题标题】:Interstitial Ad not showing (with Banner ads)插页式广告未展示(带有横幅广告)
【发布时间】:2016-08-23 17:27:15
【问题描述】:

我尝试按照 Google ADMOB 广告添加代码,但没有成功。然后我开始使用 GITHUB 示例来添加插页式广告。我的项目没有任何错误。 Eclipse 没有显示任何内容来代替广告。请查看我的代码并告诉我哪里出错了。我会在必要时突出显示内容。横幅广告有效!!!!

public class AppGame extends Activity {


AdView adView;

 /** The log tag. */
  private static final String LOG_TAG = "InterstitialSample";

  /** Your ad unit id. Replace with your actual ad unit id. */
  private static final String AD_UNIT_ID1 = "INSERT AD ID HERE";

  /** The interstitial ad. */
  private InterstitialAd interstitialAd;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdUnitId(AD_UNIT_ID1);

    // Set the AdListener.
    interstitialAd.setAdListener(new AdListener() {
      @Override
      public void onAdLoaded() {
        Log.d(LOG_TAG, "onAdLoaded");

      }

      @Override
      public void onAdFailedToLoad(int errorCode) {


        // Change the button text and disable the button.

      }
    });

}



/** Called when the Load Interstitial button is clicked. */
  public void loadInterstitial(View unusedView) {
    // Disable the show button until the new ad is loaded.

    // Check the logcat output for your hashed device ID to get test ads on a physical device.
    AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();

    // Load the interstitial ad.
    interstitialAd.loadAd(adRequest);
  }

  /** Called when the Show Interstitial button is clicked. */
  public void showInterstitial(View unusedView) {
    // Disable the show button until another interstitial is loaded.


    if (interstitialAd.isLoaded()) {
      interstitialAd.show();
    } else {
      Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");
    }
  }

  /** Gets a string error reason from an error code. */
  private String getErrorReason(int errorCode) {
    String errorReason = "";
    switch(errorCode) {
      case AdRequest.ERROR_CODE_INTERNAL_ERROR:
        errorReason = "Internal error";
        break;
      case AdRequest.ERROR_CODE_INVALID_REQUEST:
        errorReason = "Invalid request";
        break;
      case AdRequest.ERROR_CODE_NETWORK_ERROR:
        errorReason = "Network Error";
        break;
      case AdRequest.ERROR_CODE_NO_FILL:
        errorReason = "No fill";
        break;
    }
    return errorReason;
  }

  }

【问题讨论】:

  • 您已授予互联网权限并在清单中声明了``,对吗?
  • 横幅广告有效!只有插页式广告不是。
  • 那么请发布仅与插页式广告相关的代码
  • 请查看我的this答案
  • @Kunu 我检查并尝试过。同样的问题。

标签: android admob ads interstitial


【解决方案1】:

设置adunit后调用loadInterstitial(v)

 interstitialAd.setAdUnitId(AD_UNIT_ID1);
 loadInterstitial(v);

并在您想要展示广告的时间/地点致电showInterstitial(v)

【讨论】:

    【解决方案2】:

    您忘记调用 loadInterstitial 函数来加载插页式广告。

    在您的onCreate 函数中,调用loadInterstitial 函数。然后像这样添加监听器:

    interstitialAd.setAdListener(new AdListener() {
          @Override
          public void onAdLoaded() {
            Log.d(LOG_TAG, "onAdLoaded");
            interstitialAd.show();
          }
    

    或将布尔值设置为 true 并在应用中的自然断点处检查布尔值是否为 true,然后显示广告。

    【讨论】:

    • 你是对的,但我该怎么做。我想我必须像这样添加它: interstitialAd.setAdListener(new AdListener() { @Override public void onAdLoaded() { Log.d(LOG_TAG, "onAdLoaded"); View v = null; loadInterstitial(v); }
    • 请不要指示人们从#onAdLoaded() 拨打interstitial.show() 提供糟糕的用户体验,并且可能会被禁止他们的帐户
    • 我同意@William,但由于他目前有一个原型,这将表明广告确实已加载。这确实是不好的做法,因此我关于自然断点的句子。
    • 当然,但他会复制你的代码。这将使他的帐户被禁止。请不要延续这个糟糕的代码示例。
    • 不,如果他在他的应用程序中使用这种代码,他的帐户不会被 admobs 禁止。人们很可能会被激怒并卸载该应用程序或给出差评,但您不会因此而被禁止。
    【解决方案3】:

    我的一台测试设备也有同样的问题。找了这么多天。但我没有得到任何解决方案。

    最后我尝试删除代码

    .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
    

    我得到了成功的结果。

    所以在测试的最后一步尝试这样。

    【讨论】:

      【解决方案4】:

      onCreate 添加以下行

      mInterstitialAd = new InterstitialAd(this);
              // set the ad unit ID
              mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
              mInterstitialAd.setAdListener(new AdListener() {
                  @Override
                  public void onAdClosed() {
                  }
                  @Override
                  public void onAdLoaded() {
                      // Ads loaded, stop requesting
                          mInterstitialAd.show();
                     //update time start
                          timeStart = new Date().getTime();
                  }
              });
      

      onResume 检查时间显示 Intertitial Ads 并发送请求 Ads:

        if(new Date().getTime()-timeStart>=timeShowAds) {
            AdRequest adRequest = new AdRequest.Builder()
                    .addTestDevice("36E0B62FE34536712ED1BEBD85467085")
                    .build();
            // Load ads into Interstitial Ads
            mInterstitialAd.loadAd(adRequest);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-07
        • 1970-01-01
        • 2022-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多