AdManagerInterstitialAd

public abstract class AdManagerInterstitialAd extends InterstitialAd


Reklamy zajmujące całą stronę i wyświetlane w naturalnych momentach przejściowych, np. przy zmianie strony, uruchamianiu aplikacji lub wczytywaniu poziomu gry, dla wydawców Google Ad Manager. Mają przycisk zamykania, który kończy ich wyświetlanie.

Przykładowy kod:

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

        // Load a Google Ad Manager 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.
        AdManagerInterstitialAd.load(
            this,
            "myAdUnitId",
            new AdManagerAdRequest.Builder().build(),
            new AdManagerInterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull AdManagerInterstitialAd ad) {
                    adManagerInterstitialAd = ad;
                    adManagerInterstitialAd.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 (adManagerInterstitialAd != null) {
                    adManagerInterstitialAd.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");
    }
}

Podsumowanie

Konstruktory publiczne

Metody publiczne

abstract @Nullable AppEventListener

Zwraca wartość AppEventListener dla tego AdManagerInterstitialAd.

static void
load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdManagerAdRequest adManagerAdRequest,
    @NonNull AdManagerInterstitialAdLoadCallback loadCallback
)

Ładuje AdManagerInterstitialAd.

abstract void

Ustawia AppEventListener dla tego AdManagerInterstitialAd.

Metody dziedziczone

Z com.google.android.gms.ads.interstitial.InterstitialAd
abstract @NonNull String

Zwraca identyfikator jednostki reklamowej.

abstract @Nullable FullScreenContentCallback

Pobiera FullScreenContentCallback dla tego InterstitialAd.

abstract @Nullable OnPaidEventListener

Pobiera OnPaidEventListener dla tego InterstitialAd.

abstract @NonNull ResponseInfo

Zwraca obiekt ResponseInfo dla wczytanej reklamy.

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

Ta metoda została wycofana.

Zamiast tego użyj funkcji isAdAvailable.

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

Ładuje InterstitialAd.

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

Ta metoda została wycofana.

Zamiast tego użyj typu reklamy pollAd.

abstract void

Rejestruje funkcję wywołania zwrotnego, która jest wywoływana, gdy wyświetlane są reklamy i treści pełnoekranowe.

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

Ustawia flagę, która określa, czy ten obiekt reklamy przejściowej będzie wyświetlany w trybie pełnoekranowym.

abstract void

Rejestruje wywołanie zwrotne, które zostanie wywołane, gdy ta reklama według szacunków zarobiła pieniądze.

abstract void
show(@NonNull Activity activity)

Wyświetla reklamę pełnoekranową.

Konstruktory publiczne

AdManagerInterstitialAd

public AdManagerInterstitialAd()

Metody publiczne

getAppEventListener

public abstract @Nullable AppEventListener getAppEventListener()

Zwraca wartość AppEventListener dla tego AdManagerInterstitialAd.

ładunek

public static void load(
    @NonNull Context context,
    @NonNull String adUnitId,
    @NonNull AdManagerAdRequest adManagerAdRequest,
    @NonNull AdManagerInterstitialAdLoadCallback loadCallback
)

Ładuje AdManagerInterstitialAd.

Parametry
@NonNull Context context

Kontekst.

@NonNull String adUnitId

Identyfikator jednostki reklamowej.

@NonNull AdManagerAdRequest adManagerAdRequest

Żądanie reklamy z informacjami kierowania.

@NonNull AdManagerInterstitialAdLoadCallback loadCallback

Wywołanie zwrotne, które zostanie wywołane po zakończeniu wczytywania reklamy przejściowej Google Ad Managera.

setAppEventListener

public abstract void setAppEventListener(@Nullable AppEventListener appEventListener)

Ustawia AppEventListener dla tego AdManagerInterstitialAd.