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

แสดงรหัสหน่วยโฆษณา

abstract FullScreenContentCallback?

รับ FullScreenContentCallback สำหรับ InterstitialAd นี้

abstract OnPaidEventListener?

รับ OnPaidEventListener สำหรับ InterstitialAd นี้

abstract Long

แสดงรหัสตำแหน่งสำหรับ InterstitialAd นี้

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)

ตั้งค่า Flag ที่ควบคุมว่าจะแสดงออบเจ็กต์โฆษณาคั่นระหว่างหน้าในโหมดสมจริงหรือไม่

abstract Unit

ลงทะเบียนฟังก์ชันเรียกกลับที่จะเรียกใช้เมื่อระบบประเมินว่าโฆษณานี้สร้างรายได้

abstract Unit
setPlacementId(placementId: Long)

ตั้งรหัสตําแหน่งสําหรับโฆษณาคั่นระหว่างหน้า

abstract Unit
show(activity: Activity)

แสดงโฆษณาคั่นระหว่างหน้า

ผู้รับเหมาสาธารณะ

InterstitialAd

InterstitialAd()

ฟังก์ชันสาธารณะ

getAdUnitId

abstract fun getAdUnitId(): String

แสดงรหัสหน่วยโฆษณา

getFullScreenContentCallback

abstract fun getFullScreenContentCallback(): FullScreenContentCallback?

รับ FullScreenContentCallback สำหรับ InterstitialAd นี้

getOnPaidEventListener

abstract fun getOnPaidEventListener(): OnPaidEventListener?

รับ OnPaidEventListener สำหรับ InterstitialAd นี้

getPlacementId

abstract fun getPlacementId(): Long

แสดงรหัสตำแหน่งสำหรับ InterstitialAd นี้

getResponseInfo

abstract fun getResponseInfo(): ResponseInfo

แสดงผลออบเจ็กต์ ResponseInfo สำหรับโฆษณาที่โหลด แสดงผล null จนกว่าโฆษณาจะโหลดสําเร็จ

isAdAvailable

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

แสดงผล true หากมีโฆษณาคั่นระหว่างหน้าที่โหลดจาก startPreload

โหลด

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

โหลด InterstitialAd

พารามิเตอร์
context: Context

บริบทของกิจกรรมหรือแอปพลิเคชัน

adUnitId: String

รหัสหน่วยโฆษณา

adRequest: AdRequest

คำขอโฆษณาที่มีข้อมูลการกำหนดเป้าหมาย

loadCallback: InterstitialAdLoadCallback

Callback ที่จะเรียกใช้เมื่อโฆษณาคั่นระหว่างหน้าโหลดเสร็จ

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

ตั้งค่า Flag ที่ควบคุมว่าจะแสดงออบเจ็กต์โฆษณาคั่นระหว่างหน้าในโหมดสมจริงหรือไม่ เรียกใช้เมธอดนี้ก่อน show ในระหว่าง show หากเปิดแฟล็กนี้และรองรับโหมด Immersive ระบบจะเปิด SYSTEM_UI_FLAG_IMMERSIVE_STICKY และ SYSTEM_UI_FLAG_HIDE_NAVIGATION สำหรับโฆษณาคั่นระหว่างหน้า

setOnPaidEventListener

abstract fun setOnPaidEventListener(listener: OnPaidEventListener?): Unit

ลงทะเบียนฟังก์ชันเรียกกลับที่จะเรียกใช้เมื่อระบบประเมินว่าโฆษณานี้สร้างรายได้

setPlacementId

abstract fun setPlacementId(placementId: Long): Unit

ตั้งรหัสตําแหน่งสําหรับโฆษณาคั่นระหว่างหน้า

เรียกใช้เมธอดนี้ก่อนแสดงโฆษณาเพื่อให้มั่นใจว่าระบบจะรวมรหัสตำแหน่งนี้ไว้ในการรายงาน

พารามิเตอร์
placementId: Long

จำนวนเต็มแบบยาวที่ UI ของ AdMob ระบุสำหรับตําแหน่งที่กําหนดค่า

แสดง

abstract fun show(activity: Activity): Unit

แสดงโฆษณาคั่นระหว่างหน้า

พารามิเตอร์
activity: Activity

Activityบริบทที่จะใช้แสดงโฆษณา