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 long

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

abstract @NonNull ResponseInfo

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

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

這個方法已淘汰。

請改用 isAdAvailable。

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)

這個方法已淘汰。

請改用 pollAd。

abstract void

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

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

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

abstract void

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

abstract void
setPlacementId(long placementId)

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

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

getPlacementId

public abstract long getPlacementId()

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

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)

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

setPlacementId

public abstract void setPlacementId(long placementId)

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

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

參數
long placementId

AdMob UI 針對已設定的刊登位置顯示的長整數。

show

public abstract void show(@NonNull Activity activity)

顯示插頁式廣告。

參數
@NonNull Activity activity

用來呈現廣告的 Activity 情境。