Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HUAWEI HMS Core
Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.
Interstitial ads are full-screen ads that cover the interface of an app. Such ads are displayed when a user starts, pauses, or exits an app, without disrupting the user's experience.
Create an InterstitialAd object and use the setAdId() method of the InterstitialAd class to set a test ad slot ID. The sample code is as follows:
- private void loadInterstitialAd() {
- interstitialAd = new InterstitialAd(this);
- interstitialAd.setAdId("testb4znbuh3n2"); // testb4znbuh3n2 is a dedicated test ad slot ID.
- ...
- }
Call the loadAd() method of the InterstitialAd object to load an ad. The sample code is as follows:
- private void loadInterstitial() {
- AdParam adParam = new AdParam.Builder().build();
- interstitialAd.loadAd(adParam);
- ...
- }
Call the isLoaded() method to confirm that an ad has finished loading, and call the show() method of the InterstitialAd object to display the ad.
- private void showInterstitial() {
- if (interstitialAd != null && interstitialAd.isLoaded()) {
- interstitialAd.show();
- } else {
- Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
- }
- }
Call the setAdListener method of the InterstitialAd class to add the ad event listener AdListener for the InterstitialAd object, and implement the methods in AdListener to listen to ad events.
- ...
- interstitialAd.setAdListener(adListener);
- ...
- private AdListener adListener = new AdListener() {
- @Override
- public void onAdLoaded() {
- // Called when an ad is loaded successfully.
- ...
- showInterstitialAd();
- }
- @Override
- public void onAdFailed(int errorCode) {
- // Called when an ad fails to be loaded.
- }
- @Override
- public void onAdClosed() {
- // Called when an ad is closed.
- }
- @Override
- public void onAdClicked() {
- // Called when an ad is clicked.
- }
- @Override
- public void onAdLeave() {
- // Called when a user leaves an ad.
- }
- @Override
- public void onAdOpened() {
- // Called when an ad is opened.
- }
- @Override
- public void onAdImpression() {
- // Called when an ad impression occurs.
- }
- };
- ...
For details about the methods in AdListener, please refer to the API Reference.
When testing interstitial ads, use the dedicated test ad slot ID to obtain test ads. This avoids invalid ad clicks during the test. The test ad slot ID is used only for function commissioning, but not for ad monetization. Before releasing your app, apply for a formal ad slot ID and replace the test ad slot ID with the formal one.
The following table lists the dedicated ad slot ID for interstitial ad testing.
Ad Format | Display Form | Screen Orientation | Size | Test Ad Slot ID |
Interstitial | Image | Portrait | 1080 x 1620 | teste9ih9j0rc3 |
Interstitial | Video | Portrait | 720 x 1080 | testb4znbuh3n2 |
You can download the sample code for interstitial ads and execute the code. The following screen will be displayed.

Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.