AdManagerInterstitialAd

abstract class AdManagerInterstitialAd : InterstitialAd


在自然轉換點 (例如網頁切換、應用程式啟動或遊戲關卡載入時) 呈現的全版廣告體驗,適用於 Google Ad Manager 發布商。插頁式廣告有關閉按鈕,使用者可自行移除廣告。

程式碼範例:

public class MyActivity extends Activity {
    private AdManagerInterstitialAd adManagerInterstitialAd;
    private Button nextLevelButton;
    private TextView textView;

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

        // Create a full screen content callback.
        FullScreenContentCallback fullScreenContentCallback = new FullScreenContentCallback() {
            @Override
            public void onAdDismissedFullScreenContent() {
               adManagerInterstitialAd = null;
               // Proceed to the next level.
               goToNextLevel();
            }
        };

        // Load a Google Ad Manager interstitial ad. When a natural transition in the app occurs
        // (such as a level ending in a game), show the interstitial. In this simple example, the
        // press of a button is used instead.
        //
        // If the button is clicked before the interstitial is loaded, the user should proceed to
        // the next part of the app (in this case, the next level).
        //
        // If the interstitial is finished loading, the user will view the interstitial before
        // proceeding.
        AdManagerInterstitialAd.load(
            this,
            "myAdUnitId",
            new AdManagerAdRequest.Builder().build(),
            new AdManagerInterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull AdManagerInterstitialAd ad) {
                    adManagerInterstitialAd = ad;
                    adManagerInterstitialAd.setFullScreenContentCallback(
                        fullScreenContentCallback);
                }

                @Override
                public void onAdFailedToLoad(@NonNull LoadAdError adError) {
                    // Code to be executed when an ad request fails.
                }
            });

        // Create the button to go to the next level.
        nextLevelButton = new Button(this);
        nextLevelButton.setText("Next Level");
        nextLevelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Show the interstitial if it is ready. Otherwise, proceed to the next level
                // without ever showing it.
                if (adManagerInterstitialAd != null) {
                    adManagerInterstitialAd.show(MyActivity.this);
                } else {
                    // Proceed to the next level.
                    goToNextLevel();
                }
            }
        });

        // Add the next level button to the layout.
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.addView(nextLevelButton);

        // Create a TextView to display the current level.
        textView = new TextView(this);
        textView.setText("Level 1");
        layout.addView(textView);

        setContentView(layout);
    }

    public void goToNextLevel() {
        // Show the next level, and disable the next level button since there are no more levels.
        nextLevelButton.setEnabled(false);
        textView.setText("Level 2");
    }
}

摘要

公用建構函式

公開函式

abstract AppEventListener?

傳回這個 AdManagerInterstitialAd 的 AppEventListener。

java-static Unit
load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: AdManagerInterstitialAdLoadCallback
)

載入 AdManagerInterstitialAd。

abstract Unit

為這個 AdManagerInterstitialAd 設定 AppEventListener。

繼承函式

來自 com.google.android.gms.ads.interstitial.InterstitialAd
abstract String

傳回廣告單元 ID。

abstract FullScreenContentCallback?

取得這個 InterstitialAd 的 FullScreenContentCallback。

abstract OnPaidEventListener?

取得這個 InterstitialAd 的 OnPaidEventListener。

abstract Long

傳回這個 InterstitialAd 的刊登位置 ID。

abstract ResponseInfo

傳回已載入廣告的 ResponseInfo 物件。

java-static Boolean
isAdAvailable(context: Context, adUnitId: String)

這個函式已淘汰。

請改用 isAdAvailable。

java-static Unit
load(
    context: Context,
    adUnitId: String,
    adRequest: AdRequest,
    loadCallback: InterstitialAdLoadCallback
)

載入 InterstitialAd。

java-static InterstitialAd?
pollAd(context: Context, adUnitId: String)

這個函式已淘汰。

請改用 pollAd。

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

註冊回呼,廣告顯示及關閉全螢幕內容時叫用。

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

設定標記,控管是否以沉浸模式顯示這個插頁式物件。

abstract Unit

註冊回呼,預估這則廣告有收益時叫用。

abstract Unit
setPlacementId(placementId: Long)

設定插頁式廣告的刊登位置 ID。

abstract Unit
show(activity: Activity)

顯示插頁式廣告。

公用建構函式

AdManagerInterstitialAd

AdManagerInterstitialAd()

公開函式

getAppEventListener

abstract fun getAppEventListener(): AppEventListener?

傳回這個 AdManagerInterstitialAd 的 AppEventListener。

load

java-static fun load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: AdManagerInterstitialAdLoadCallback
): Unit

載入 AdManagerInterstitialAd。

參數
context: Context

背景資訊。

adUnitId: String

廣告單元 ID。

adManagerAdRequest: AdManagerAdRequest

有指定目標資訊的廣告請求。

loadCallback: AdManagerInterstitialAdLoadCallback

Google Ad Manager 插頁式廣告載入完成時叫用的回呼。

setAppEventListener

abstract fun setAppEventListener(appEventListener: AppEventListener?): Unit

為這個 AdManagerInterstitialAd 設定 AppEventListener。