InterstitialAd

abstract class InterstitialAd

已知的直接子類別
AdManagerInterstitialAd

在自然轉換點 (例如網頁切換、應用程式啟動或遊戲關卡載入時) 顯示的全版廣告體驗,適用於 Google Ad Manager 發布商。


在自然轉換點 (例如網頁切換、應用程式啟動或遊戲關卡載入時) 顯示的全版廣告體驗。插頁廣告上會有一個關閉按鈕,讓使用者可以移除廣告。

程式碼範例:

public class MyActivity extends Activity {
    private InterstitialAd interstitialAd;
    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() {
               interstitialAd = null;
               // Proceed to the next level.
               goToNextLevel();
            }
        };

        // Load an 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.
        InterstitialAd.load(
            this,
            "myAdUnitId",
            new AdRequest.Builder().build(),
            new InterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull InterstitialAd ad) {
                    interstitialAd = ad;
                    interstitialAd.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 (interstitialAd != null) {
                    interstitialAd.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 String

傳回廣告單元 ID。

abstract FullScreenContentCallback?

取得這個 InterstitialAdFullScreenContentCallback

abstract OnPaidEventListener?

取得這個 InterstitialAdOnPaidEventListener

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)

顯示插頁式廣告。

公用建構函式

InterstitialAd

InterstitialAd()

公開函式

getAdUnitId

abstract fun getAdUnitId(): String

傳回廣告單元 ID。

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

取得這個 InterstitialAdFullScreenContentCallback

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

取得這個 InterstitialAdOnPaidEventListener

getPlacementId

abstract fun getPlacementId(): Long

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

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

傳回已載入廣告的 ResponseInfo 物件。廣告成功載入前,會傳回 null

isAdAvailable

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

如果從 startPreload 載入可用的插頁式廣告,就會傳回 true

load

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

載入 InterstitialAd

參數
context: Context

活動或應用程式內容。

adUnitId: String

廣告單元 ID。

adRequest: AdRequest

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

loadCallback: InterstitialAdLoadCallback

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

pollAd

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

startPreload 擷取載入的下一個插頁式廣告,如果沒有廣告,則擷取 null

setFullScreenContentCallback

abstract fun setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
): Unit

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

setImmersiveMode

abstract fun setImmersiveMode(immersiveModeEnabled: Boolean): Unit

設定旗標,控管是否要在沉浸模式中顯示這個中繼物件。請在 show 之前呼叫這個方法。在 show 期間,如果這個旗標處於開啟狀態,且系統支援沉浸模式,系統就會為插頁式廣告開啟 SYSTEM_UI_FLAG_IMMERSIVE_STICKY 和 SYSTEM_UI_FLAG_HIDE_NAVIGATION。

setOnPaidEventListener

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

註冊回呼,在預估這則廣告已賺取收益時叫用。

setPlacementId

abstract fun setPlacementId(placementId: Long): Unit

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

為確保報表會納入這個刊登位置 ID,請在顯示廣告前呼叫這個方法。

參數
placementId: Long

AdMob 使用者介面為已設定的刊登位置提供的長整數。

顯示

abstract fun show(activity: Activity): Unit

顯示插頁式廣告。

參數
activity: Activity

Activity顯示廣告的背景脈絡。