Skip to content

插屏广告
Interstitial Ads

参考Demo

ReferenceDemo

注意: 如果聚合集成了腾讯广告,则触发展示插屏广告的Activity需要配置:

**Note: If Tencent Ads is integrated with the aggregation, the Activity that triggers the display of interstitial ads needs to be configured:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

1. 主要API
Main API

1.1 WMInterstitialAd

  • com.windmill.sdk.interstitial.WMInterstitialAd
方法名
Method
方法介绍
Method Introduction
WMInterstitialAd(Activity activity, WMInterstitialAdRequest request)构造方法。参数说明:activity(展示广告的 activity)、request(广告请求对象)。
Constructor. Parameter description: activity (activity to display ads), request (ad request object).
setInterstitialAdListener(WMInterstitialAdListener interstitialAdListener)回调监听。广告相关状态会通过 interstitialAdListener 通知开发者。
Callback listener. Ad related status will be notified to the developer through interstitialAdListener.
loadAd()拉取广告。
Load ads.
isReady()广告是否准备好,未准备好广告将无法展示。
Whether the ad is ready. If it is not ready, the ad will not be displayed.
show(Activity activity, HashMap<String, String> options)展示广告。参数说明:activity(展示广告的 activity)、options(广告展示时的扩展参数,可选,可参考demo)。
Display ads. Parameter description: activity (activity to display ads), options (extended parameters for ad display, optional, refer to demo).
checkValidAdCaches()查询当前广告位的所有缓存信息的AdInfo对象、在广告加载成功后调用。
Query the AdInfo object of all cached information of the current ad slot and call it after the ad is loaded successfully.
destroy()销毁广告。
Destroy ads.

1.2 WMInterstitialAdRequest

  • com.windmill.sdk.interstitial.WMInterstitialAdRequest
方法名
Method
方法介绍
Method Introduction
WMInterstitialAdRequest(String placementId, String userId, Map<String, Object> options)构造方法。参数说明:placementId(广告位Id)、userId(用户Id可选)、options(扩展参数,可传任意)。
Constructor. Parameter description: placementId (ad slot ID), userId (user ID is optional), options (extended parameters, any parameters can be passed).

1.3 WMInterstitialAdListener

  • com.windmill.sdk.interstitial.WMInterstitialAdListener
方法名
Method
方法介绍
Method Introduction
onInterstitialAdLoadSuccess(String placementId)广告成功加载。参数说明:placementId(广告位Id)。
The ad was loaded successfully. Parameter description: placementId (ad slot Id).
onInterstitialAdLoadError(WindMillError error, String placementId)广告加载失败。参数说明:error(报错信息,具体可看其内部code和message)、placementId(报错的广告位Id)。
Ad loading failed. Parameter description: error (error information, see its internal code and message for details), placementId (the ID of the ad position where the error was reported).
onInterstitialAdPlayStart(AdInfo adInfo)广告成功展示,媒体可在此记录曝光。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
The advertisement is successfully displayed, and the media can record the exposure here. Parameter description: adInfo (advertising information, see its internal member variables for details).
onInterstitialAdPlayError(WindMillError error, String placementId)广告播放出错。参数说明:error(报错信息,具体可看其内部code和message)、placementId(报错的广告位Id)。
Ad playback error. Parameter description: error (error information, see its internal code and message for details), placementId (the ID of the ad position where the error was reported).
onInterstitialAdPlayEnd(AdInfo adInfo)广告播放结束。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
Advertisement playback ends. Parameter description: adInfo (advertisement information, see its internal member variables for details).
onInterstitialAdClicked(AdInfo adInfo)广告被点击。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
The ad was clicked. Parameter description: adInfo (ad information, see its internal member variables for details).
onInterstitialAdClosed(AdInfo adInfo)广告关闭。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
Advertisement is turned off. Parameter description: adInfo (advertisement information, see its internal member variables for details).

2. 接入代码示例
Code example

2.1 设置监听回调
Setting the listener callback

java
private WMInterstitialAd interstitialAd;

/**
 * PLACEMENT_ID 必填
 * USER_ID 可选
 * OPTIONS 自定义参数 可选
 */
WMInterstitialAdRequest request = new WMInterstitialAdRequest(PLACEMENT_ID, USER_ID, OPTIONS);

interstitialAd = new WMInterstitialAd(this, request);

interstitialAd.setInterstitialAdListener(new WMInterstitialAdListener() {
    @Override
    public void onInterstitialAdLoadSuccess(String placementId) {

    }

    @Override
    public void onInterstitialAdPlayStart(AdInfo adInfo) {

    }

    @Override
    public void onInterstitialAdPlayEnd(AdInfo adInfo) {

    }

    @Override
    public void onInterstitialAdClicked(AdInfo adInfo) {

    }

    @Override
    public void onInterstitialAdClosed(AdInfo adInfo) {

    }

    /**
     * 加载广告错误回调
     * WindMillError 插屏错误内容
     * placementId 广告位
     */
    @Override
    public void onInterstitialAdLoadError(final WindMillError error, final String placementId) {

    }

    /**
     * 播放错误回调
     * WindMillError 插屏错误内容
     * placementId 广告位
     */
    @Override
    public void onInterstitialAdPlayError(final WindMillError error, final String placementId) {

    }
});

2.2 插屏广告加载
Interstitial Ad Loading

java
/**
 *同一个WMInterstitialAd不建议在广告playing中重复load
 *同一个WMInterstitialAd在onInterstitialAdClosed中可以load下一次广告
 */
if (interstitialAd != null) {
    interstitialAd.loadAd();
}

2.3 插屏广告播放
Interstitial Ad Playback

java
/**
 * 收到onInterstitialAdLoadSuccess回调代表广告已ready
 * option 自定义参数(可选)
 */
if (interstitialAd != null && interstitialAd.isReady()) {
    //广告播放
    HashMap option = new HashMap();
        option.put(WMConstants.AD_SCENE_ID, "567");
        option.put(WMConstants.AD_SCENE_DESC, "转盘抽奖");
    interstitialAd.show(this, option);
}

2.4 插屏广告预加载注意事项
Precautions for preloading interstitial ads

  • 需要在平台开启预加载功能。

The preloading function needs to be enabled on the platform.

  • 开启预加载功能后,sdk内部会在广告播放中再次去请求广告,成功后会再次回调onInterstitialAdLoadSuccess。(相当于load一次广告会有两次onInterstitialAdLoadSuccess

After the preloading function is enabled, the SDK will request ads again during ad playback, and onInterstitialAdLoadSuccess will be called back again if successful. ( This is equivalent to loading an ad once and calling onInterstitialAdLoadSuccess twice .)

  • 开启预加载功能后,要注意全局使用同一个WMInterstitialAd对象。(new注意判null

After enabling the preloading function, be sure to use the same WMInterstitialAd object globally. ( Note that new is null .)

  • 广告播放时可先判断isReady(),如果ready直接播放,否则可再次调用loadAd()。

When playing an ad, you can first check isReady(). If it is ready, play it directly. Otherwise, call loadAd() again.

java
private WMInterstitialAd mInterstitialAd;;//全局对象

    /**
     * 加载广告
     */
    private void loadAd() {

        if (mInterstitialAd == null) {
            mInterstitialAd = new WMInterstitialAd(this, new WMInterstitialAdRequest(placementId, userID, options));
        }

        mInterstitialAd.setInterstitialAdListener(new WMInterstitialAdListener() {
            @Override
            public void onInterstitialAdLoadSuccess(String s) {

            }

            @Override
            public void onInterstitialAdPlayStart(AdInfo adInfo) {

            }

            @Override
            public void onInterstitialAdPlayEnd(AdInfo adInfo) {

            }

            @Override
            public void onInterstitialAdClicked(AdInfo adInfo) {

            }

            @Override
            public void onInterstitialAdClosed(AdInfo adInfo) {

            }

            @Override
            public void onInterstitialAdLoadError(WindMillError windMillError, String s) {

            }

            @Override
            public void onInterstitialAdPlayError(WindMillError windMillError, String s) {

            }
        });

        mInterstitialAd.loadAd();
    }