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 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
show(activity: Activity)

展示插页式广告。

公共构造函数

InterstitialAd

InterstitialAd()

公共函数

getAdUnitId

abstract fun getAdUnitId(): String

返回广告单元 ID。

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

获取此 InterstitialAdFullScreenContentCallback

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

获取此 InterstitialAdOnPaidEventListener

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

返回已加载广告的 ResponseInfo 对象。在广告成功加载之前,返回 null

isAdAvailable

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

如果有可用的插页式广告从 startPreload 加载,则返回 true

负荷

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

加载 InterstitialAd

参数
context: Context

activity 或应用上下文。

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

注册一个回调,以便在系统估算此广告赚取了收入时调用该回调。

显示

abstract fun show(activity: Activity): Unit

展示插页式广告。

参数
activity: Activity

用于展示广告的 Activity 上下文。