InterstitialAd

public 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 @NonNull String

傳回廣告單元 ID。

abstract @Nullable FullScreenContentCallback

取得此 InterstitialAdFullScreenContentCallback

abstract @Nullable OnPaidEventListener

取得此 InterstitialAdOnPaidEventListener

abstract @NonNull ResponseInfo

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

static boolean
isAdAvailable(@NonNull Context context, @NonNull String adUnitId)

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

static void
load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdRequest adRequest,
    @NonNull InterstitialAdLoadCallback loadCallback
)

載入 InterstitialAd

static @Nullable InterstitialAd
pollAd(@NonNull Context context, @NonNull String adUnitId)

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

abstract void

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

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

設定旗標,用於控制是否要在沉浸式模式中顯示這個插播物件。

abstract void

在系統預估此廣告可賺取收益時,註冊要叫用的回呼。

abstract void
show(@NonNull Activity activity)

顯示插頁式廣告。

公用建構函式

InterstitialAd

public InterstitialAd()

公用方法

getAdUnitId

public abstract @NonNull String getAdUnitId()

傳回廣告單元 ID。

getFullScreenContentCallback

public abstract @Nullable FullScreenContentCallback getFullScreenContentCallback()

取得此 InterstitialAdFullScreenContentCallback

getOnPaidEventListener

public abstract @Nullable OnPaidEventListener getOnPaidEventListener()

取得此 InterstitialAdOnPaidEventListener

getResponseInfo

public abstract @NonNull ResponseInfo getResponseInfo()

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

isAdAvailable

public static boolean isAdAvailable(@NonNull Context context, @NonNull String adUnitId)

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

load

public static void load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdRequest adRequest,
    @NonNull InterstitialAdLoadCallback loadCallback
)

載入 InterstitialAd

參數
@NonNull Context context

活動或應用程式結構定義。

@NonNull String adUnitId

廣告單元 ID。

@NonNull AdRequest adRequest

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

@NonNull InterstitialAdLoadCallback loadCallback

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

pollAd

public static @Nullable InterstitialAd pollAd(@NonNull Context context, @NonNull String adUnitId)

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

setFullScreenContentCallback

public abstract void setFullScreenContentCallback(
    @Nullable FullScreenContentCallback fullScreenContentCallback
)

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

setImmersiveMode

public abstract void setImmersiveMode(boolean immersiveModeEnabled)

設定旗標,用於控制是否要在沉浸式模式中顯示這個插播物件。請在 show 之前呼叫此方法。在 show 期間,如果此標記已開啟且支援沈浸式模式,系統會為插頁式廣告開啟 SYSTEM_UI_FLAG_IMMERSIVE_STICKY 和 SYSTEM_UI_FLAG_HIDE_NAVIGATION。

setOnPaidEventListener

public abstract void setOnPaidEventListener(@Nullable OnPaidEventListener listener)

在系統預估此廣告可賺取收益時,註冊要叫用的回呼。

顯示

public abstract void show(@NonNull Activity activity)

顯示插頁式廣告。

參數
@NonNull Activity activity

用於顯示廣告的 Activity 內容。