开屏广告

开屏广告

此章节将演示如何请求在原生环境下请求与展示开屏广告

开屏广告在 App 启动时展现。用户可以点击广告跳转到广告落地页,或者点击右上角的跳过按钮,跳转到 App 内容首页

全屏半屏
开屏广告全屏开屏广告半屏

请求开屏广告

调用ZJSplashAd#loadAd的重载方法请求广告,并在ZJSplashAdLoadListener中获取广告对象与处理错误信息

public class ZJSplashAd {

    public static void loadAd(Activity activity, @NonNull String posId, ZJSplashAdLoadListener loadListener);

    /**
     * 加载广告
     *
     * @param activity     当前Activity
     * @param posId        广告位ID
     * @param widthDP      期望宽,单位DP,部分联盟需要额外配置
     * @param heightDP     期望高,单位DP,部分联盟需要额外配置
     * @param loadListener 加载回调
     */
    public static void loadAd(Activity activity, String posId, int widthDP, int heightDP, ZJSplashAdLoadListener loadListener);

}

加载回调说明

方法说明
onError(int code, String msg)广告加载出错
code: 错误码
msg: 错误信息
onAdLoaded(ZJSplashAd splashAd)广告加载成功
splashAd: 广告对象

提示

开屏报错找不到广告位SDK初始化失败等问题见常见问题-开屏

展示开屏广告

在加载成功回调中获取到ZJSplashAd对象后,可以配置交互回调,并展示广告

ZJSplashAd 说明

方法说明
setAdInteractionListener(ZJSplashAdInteractionListener interactionListener)配置交互回调
show(ViewGroup container)传入广告容器展示

注意

开屏广告容器需要width == 100% 屏幕宽height >= 90% 屏幕高,否则会影响计费

交互回调说明

方法说明
onSplashAdShow()广告展示
onSplashAdClick()广告点击
onSplashAdShowError(int code, String msg)广告展示失败
code: 错误码
msg: 错误信息
onSplashAdClose()广告关闭

开屏广告接入示例

// 加载广告
ZJSplashAd.loadAd(this, posId, new ZJSplashAdLoadListener() {

    @Override
    public void onError(int code, @NonNull String msg) {
        Log.e("ZJSplashAd", "开屏广告加载出错" + code + "-" + msg);        
    }

    @Override
    public void onAdLoaded(@NonNull ZJSplashAd splashAd) {
        // 广告加载成功,配置交互回调
        splashAd.setAdInteractionListener(SplashActivity.this);
        splashAd.show(this.container);
    }

});
// 加载广告
ZJSplashAd.loadAd(this, posId, object : ZJSplashAdLoadListener {
    
    override fun onError(code: Int, msg: String) {
        Log.e("ZJSplashAd", "开屏广告加载出错$code-$msg")
    }

    override fun onAdLoaded(splashAd: ZJSplashAd) {
        // 广告加载成功,配置交互回调
        splashAd.setAdInteractionListener(this@SplashActivity)
        splashAd.show(this@SplashActivity.container)
    }

})