InterstitialAd

public abstract class InterstitialAd

Các lớp con trực tiếp đã biết
AdManagerInterstitialAd

Trải nghiệm quảng cáo toàn trang ở các điểm chuyển tiếp tự nhiên, chẳng hạn như chuyển trang, khởi động ứng dụng hoặc tải cấp độ trò chơi cho nhà xuất bản Google Ad Manager.


Trải nghiệm quảng cáo toàn trang ở các điểm chuyển tiếp tự nhiên, chẳng hạn như chuyển trang, khởi động ứng dụng hoặc tải cấp độ trò chơi. Quảng cáo xen kẽ sử dụng nút đóng để xoá quảng cáo khỏi trải nghiệm của người dùng.

Mã mẫu:

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");
    }
}

Tóm tắt

Hàm khởi tạo công khai

Phương thức công khai

abstract @NonNull String

Trả về mã đơn vị quảng cáo.

abstract @Nullable FullScreenContentCallback

Lấy FullScreenContentCallback cho InterstitialAd này.

abstract @Nullable OnPaidEventListener

Lấy OnPaidEventListener cho InterstitialAd này.

abstract @NonNull ResponseInfo

Trả về đối tượng ResponseInfo cho quảng cáo đã tải.

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

Phương thức này không còn được dùng nữa.

Thay vào đó, hãy sử dụng isAdAvailable.

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

Tải InterstitialAd.

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

Phương thức này không còn được dùng nữa.

Thay vào đó, hãy sử dụng pollAd.

abstract void

Đăng ký lệnh gọi lại để gọi khi quảng cáo hiển thị và đóng nội dung toàn màn hình.

abstract void
setImmersiveMode(boolean immersiveModeEnabled)

Đặt một cờ kiểm soát xem đối tượng xen kẽ này có hiển thị ở chế độ chìm đắm hay không.

abstract void

Đăng ký lệnh gọi lại để được gọi khi quảng cáo này được ước tính là đã kiếm được tiền.

abstract void
show(@NonNull Activity activity)

Hiển thị quảng cáo xen kẽ.

Hàm khởi tạo công khai

InterstitialAd

public InterstitialAd()

Phương thức công khai

getAdUnitId

public abstract @NonNull String getAdUnitId()

Trả về mã đơn vị quảng cáo.

getFullScreenContentCallback

public abstract @Nullable FullScreenContentCallback getFullScreenContentCallback()

Lấy FullScreenContentCallback cho InterstitialAd này.

getOnPaidEventListener

public abstract @Nullable OnPaidEventListener getOnPaidEventListener()

Lấy OnPaidEventListener cho InterstitialAd này.

getResponseInfo

public abstract @NonNull ResponseInfo getResponseInfo()

Trả về đối tượng ResponseInfo cho quảng cáo đã tải. Trả về null cho đến khi quảng cáo tải thành công.

isAdAvailable

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

Trả về true nếu có quảng cáo xen kẽ hiện có được tải từ startPreload.

trọng tải

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

Tải InterstitialAd.

Thông số
@NonNull Context context

Hoạt động hoặc ngữ cảnh ứng dụng.

@NonNull String adUnitId

Mã đơn vị quảng cáo.

@NonNull AdRequest adRequest

Yêu cầu quảng cáo có thông tin nhắm mục tiêu.

@NonNull InterstitialAdLoadCallback loadCallback

Lệnh gọi lại được gọi khi quảng cáo xen kẽ tải xong.

pollAd

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

Truy xuất quảng cáo xen kẽ tiếp theo được tải từ startPreload hoặc null nếu không có quảng cáo nào.

setFullScreenContentCallback

public abstract void setFullScreenContentCallback(
    @Nullable FullScreenContentCallback fullScreenContentCallback
)

Đăng ký lệnh gọi lại để gọi khi quảng cáo hiển thị và đóng nội dung toàn màn hình.

setImmersiveMode

public abstract void setImmersiveMode(boolean immersiveModeEnabled)

Đặt một cờ kiểm soát xem đối tượng xen kẽ này có hiển thị ở chế độ chìm đắm hay không. Gọi phương thức này trước show. Trong show, nếu cờ này đang bật và chế độ chìm được hỗ trợ, thì SYSTEM_UI_FLAG_IMMERSIVE_STICKY &SYSTEM_UI_FLAG_HIDE_NAVIGATION sẽ được bật cho quảng cáo xen kẽ.

setOnPaidEventListener

public abstract void setOnPaidEventListener(@Nullable OnPaidEventListener listener)

Đăng ký lệnh gọi lại để được gọi khi quảng cáo này được ước tính là đã kiếm được tiền.

hiện (lên)/cho thấy

public abstract void show(@NonNull Activity activity)

Hiển thị quảng cáo xen kẽ.

Thông số
@NonNull Activity activity

Ngữ cảnh Activity để hiển thị quảng cáo.