AdManagerInterstitialAd

abstract class AdManagerInterstitialAd : InterstitialAd


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

Tóm tắt

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

Hàm công khai

abstract AppEventListener?

Trả về AppEventListener cho AdManagerInterstitialAd này.

java-static Unit
load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: AdManagerInterstitialAdLoadCallback
)

Tải một AdManagerInterstitialAd.

abstract Unit

Đặt AppEventListener cho AdManagerInterstitialAd này.

Hàm kế thừa

Từ com.google.android.gms.ads.interstitial.InterstitialAd
abstract String

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

abstract FullScreenContentCallback?

Lấy FullScreenContentCallback cho InterstitialAd này.

abstract OnPaidEventListener?

Lấy OnPaidEventListener cho InterstitialAd này.

abstract Long

Trả về mã vị trí cho InterstitialAd này.

abstract ResponseInfo

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

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

Hàm này không còn được dùng nữa.

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

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

Tải một InterstitialAd.

java-static InterstitialAd?
pollAd(context: Context, adUnitId: String)

Hàm này không còn được dùng nữa.

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

abstract Unit
setFullScreenContentCallback(
    fullScreenContentCallback: FullScreenContentCallback?
)

Đăng ký một lệnh gọi lại sẽ được gọi khi quảng cáo hiển thị và loại bỏ nội dung toàn màn hình.

abstract Unit
setImmersiveMode(immersiveModeEnabled: Boolean)

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

abstract Unit

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

abstract Unit
setPlacementId(placementId: Long)

Đặt mã vị trí cho quảng cáo xen kẽ.

abstract Unit
show(activity: Activity)

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

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

AdManagerInterstitialAd

AdManagerInterstitialAd()

Hàm công khai

getAppEventListener

abstract fun getAppEventListener(): AppEventListener?

Trả về AppEventListener cho AdManagerInterstitialAd này.

trọng tải

java-static fun load(
    context: Context,
    adUnitId: String,
    adManagerAdRequest: AdManagerAdRequest,
    loadCallback: AdManagerInterstitialAdLoadCallback
): Unit

Tải một AdManagerInterstitialAd.

Thông số
context: Context

Bối cảnh.

adUnitId: String

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

adManagerAdRequest: AdManagerAdRequest

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

loadCallback: AdManagerInterstitialAdLoadCallback

Một lệnh gọi lại sẽ được gọi khi quảng cáo xen kẽ của Google Ad Manager tải xong.

setAppEventListener

abstract fun setAppEventListener(appEventListener: AppEventListener?): Unit

Đặt AppEventListener cho AdManagerInterstitialAd này.