Di chuyển quảng cáo xen kẽ

Trang này trình bày sự khác biệt trong việc tải và hiển thị quảng cáo xen kẽ giữa SDK quảng cáo trên thiết bị di động của Google (phiên bản beta) và phiên bản hiện tại.

Tải một quảng cáo

Các ví dụ sau đây tải một quảng cáo xen kẽ:

Hiện tại

Kotlin

InterstitialAd.load(
  this@InterstitialActivity,
  "AD_UNIT_ID",
  AdRequest.Builder().build(),
  object : InterstitialAdLoadCallback() {
    override fun onAdLoaded(ad: InterstitialAd) {
      // Called when an ad has loaded.
      ad.fullScreenContentCallback =
        object : FullScreenContentCallback() {
        }
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(loadAdError: LoadAdError) {
      // Called when ad fails to load.
    }
  }
)

Java

InterstitialAd.load(
  this,
  "AD_UNIT_ID",
  new AdRequest.Builder().build(),
  new InterstitialAdLoadCallback() {
    @Override
    public void onAdLoaded(@NonNull InterstitialAd ad) {
      // Called when an ad has loaded.
      ad.setFullScreenContentCallback(new FullScreenContentCallback() {});
      interstitialAd = ad;
    }

    @Override
    public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
      // Called when ad fails to load.
    }
  }
);
SDK Quảng cáo của Google trên thiết bị di động (thử nghiệm)

Kotlin

InterstitialAd.load(
  AdRequest.Builder("AD_UNIT_ID").build(),
  object : AdLoadCallback<InterstitialAd> {
    override fun onAdLoaded(ad: InterstitialAd) {
      // Called when an ad has loaded.
      ad.adEventCallback =
        object : InterstitialAdEventCallback {
        }
      interstitialAd = ad
    }

    override fun onAdFailedToLoad(loadAdError: LoadAdError) {
      // Called when ad fails to load.
    }
  }
)

Java

InterstitialAd.load(
    new AdRequest.Builder("AD_UNIT_ID").build(),
    new AdLoadCallback<InterstitialAd>() {
      @Override
      public void onAdLoaded(@NonNull InterstitialAd ad) {
        // Called when an ad has loaded.
        ad.setAdEventCallback(new InterstitialAdEventCallback() {});
        interstitialAd = ad;
      }

      @Override
      public void onAdFailedToLoad(@NonNull LoadAdError adError) {
        // Called when ad fails to load.
      }
    });

Hiển thị quảng cáo

Các ví dụ sau đây minh hoạ một quảng cáo xen kẽ:

Hiện tại

Kotlin

interstitialAd?.show(this@InterstitialActivity)

Java

interstitialAd.show(this);
SDK Quảng cáo của Google trên thiết bị di động (thử nghiệm)

Kotlin

interstitialAd?.show(this@InterstitialActivity)

Java

interstitialAd.show(this);