InterstitialAd

public abstract class InterstitialAd

既知の直接サブクラス
AdManagerInterstitialAd

Google アド マネージャーのニュース メディア向けに、ページ遷移、アプリの起動、ゲームのステージの読み込みなど、自然な画面切り替えポイントでフルページ型の広告を表示します。


ページ遷移、アプリの起動、ゲームのステージの読み込みなど、自然な画面切り替えポイントでフルページ型の広告を表示します。ボタンを押すと、インタースティシャル広告を閉じることができます。

サンプルコード:

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 コンテキスト。