Skip to content

开屏广告
Splash ads

参考Demo

ReferenceDemo

开屏广告支持点睛、开屏V+等

Splash ads support eye-catching, splash V+.

1.1 WMSplashAd

  • com.windmill.sdk.splash.WMSplashAd
方法名
Method
方法介绍
Method Introduction
WMSplashAd(Activity activity, WMSplashAdRequest adRequest, WMSplashAdListener adListener)构造方法,广告相关状态会通过 adListener 通知开发者。参数说明:activity(展示广告的 activity)、adRequest(广告请求对象)、adListener(广告状态监听器)。
Constructor, the ad-related status will be notified to the developer through adListener. Parameter description: activity (activity that displays ads), adRequest (ad request object), adListener (ad status listener).
loadAdAndShow(ViewGroup adContainer)请求并立即展示广告。参数说明:adContainer(展示广告的容器)。
Request and display ads immediately. Parameter description: adContainer (container for displaying ads).
loadAdOnly()拉取广告,配合showAd使用,实现和loadAdAndShow相同的功能。
Load ads and use with showAd to achieve the same function as loadAdAndShow.
isReady()广告是否准备好,未准备好广告将无法展示。
Whether the ad is ready. If it is not ready, the ad will not be displayed.
showAd(ViewGroup adContainer)展示广告,配合loadAdOnly使用,实现和loadAdAndShow相同的功能。
Display ads. Used with loadAdOnly to achieve the same function as loadAdAndShow.
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()当广告关闭不再使用时,必须调用此方法释放资源
When the ad is closed and no longer used, this method must be called to release resources.

1.2 WMSplashAdRequest

  • com.windmill.sdk.splash.WMSplashAdRequest
方法名
Method
方法介绍
Method Introduction
WMSplashAdRequest(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).
WMSplashAdRequest(String placementId, String userId, Map<String, Object> options, String appTitle, String appDesc, boolean disableAutoHideAd构造方法。参数说明:placementId(广告位Id)、userId(用户Id可选)、options(扩展参数,可传任意)、appTitle(广告Logo标题)、appDesc(广告Logo描述)、disableAutoHideAd(自动隐藏广告)。
Constructor. Parameter description: placementId (ad placement ID), userId (optional user ID), options (extended parameters, any parameters can be passed), appTitle (ad logo title), appDesc (ad logo description), disableAutoHideAd (auto hide ads).
setAppTitle(String appTitle)设置应用开屏LOGO标题,广告将半屏Window展示。
Set the app's opening screen LOGO title, and the ad will be displayed in a half-screen window.
setAppDesc(String appDesc)设置应用开屏LOGO描,广告半屏Window展示。
Set the app's opening screen logo to be scanned and the ad to be displayed in a half-screen window.
setDisableAutoHideAd(boolean disableAutoHideAd)广告结束,广告内容是否自动隐藏。 若开屏和应用共用Activity,建议false。若开屏是单独Activity ,建议true。
When the ad ends, should the ad content be automatically hidden? If the opening screen and the app share an Activity, false is recommended. If the opening screen is a separate Activity, true is recommended.

1.3 SplashADListener

  • com.windmill.sdk.splash.WMSplashAdListener
方法名
Method
方法介绍
Method Introduction
onSplashAdSuccessLoad(String placementId)开屏广告成功加载。参数说明:placementId(报错的广告位Id)。
The splash ad was loaded successfully. Parameter description: placementId (the ad position ID reported in the error).
onSplashAdFailToLoad(WindMillError error, String placementId)SDK开屏广告加载失败。参数说明:error(报错信息,具体可看其内部code和message)、placementId(报错的广告位Id)。
Splash 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).
onSplashAdSuccessPresent(AdInfo adInfo)开屏广告成功展示,媒体可在此记录曝光。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
The splash ad is successfully displayed, and the media can record the exposure here. Parameter description: adInfo (ad information, see its internal member variables for details).
onSplashAdClicked(AdInfo adInfo)开屏广告被点击。参数说明:adInfo(广告信息,具体可看其内部成员变量)。
The splash ad was clicked. Parameter description: adInfo (ad information, see its internal member variables for details).
onSplashClosed(AdInfo adInfo, IWMSplashEyeAd splashEyeAd)开屏广告关闭。参数说明:adInfo(广告信息,具体可看其内部成员变量)、splashEyeAd:开屏点睛广告控制接口类,开发者可通过此接口控制展示点睛广告
注意:
(1)当穿山甲、快手的开屏广告素材支持点睛时,splashEyeAd不为null。
(2)当展示的是快手开屏广告时,splashEyeAd为非null值,但不一定表示此次快手开屏广告的素材支持点睛,不支持时调用IWMSplashEyeAd#show()方法会直接回调WMSplashEyeAdListener#onAdDismiss()方法。
(3)当splashEyeAd不为null,但是开发者不想支持点睛功能时,必须调用splashEyeAd.destroy()释放资源,然后跳转主页面或者移除开屏View。
The splash ad is turned off. Parameter description: adInfo (ad information, see its internal member variables for details), splashEyeAd: splash screen ad control interface class, developers can use this interface to control the display of the splash screen ad.
Note:
(1) When the splash screen ad material of Chuanshanjia and Kuaishou supports the splash screen, splashEyeAd is not null.
(2) When the Kuaishou splash screen ad is displayed, splashEyeAd is a non-null value, but it does not necessarily mean that the material of the Kuaishou splash screen ad supports the splash screen. If it does not support it, calling the IWMSplashEyeAd#show() method will directly call back the WMSplashEyeAdListener#onAdDismiss() method.
(3) When splashEyeAd is not null, but the developer does not want to support the splash screen function, splashEyeAd.destroy() must be called to release resources, and then jump to the main page or remove the splash screen View.

1.4 IWMSplashEyeAd

  • com.windmill.sdk.splash.IWMSplashEyeAd
方法名
Method
方法介绍
Method Introduction
show(Context context, Rect rect, WMSplashEyeAdListener splashEyeAdListener)展示开屏点睛(V+、小窗)广告
context:上下文
rect:开屏点睛广告缩放动画结束时广告的显示大小,以屏幕左上角为起点(注意:快手必须传入此参数
splashEyeAdListener:开屏点睛广告事件监听器。
Display splash (V+, small window) ads
context: contextrect
: the display size of the ad when the splashEye ad scaling animation ends, starting from the upper left corner of the screen ( Note: Kuaishou must pass this parameter )
splash V+ AdListener: splashEye ad event listener
getSuggestedSize(Context context)获取缩放动画结束时推荐显示的广告大小
(目前只有穿山甲会返回,建议优先使用此大小)。
Get the recommended ad size to be displayed when the zoom animation ends(currently only CSJ will return, it is recommended to use this size first)
getSplashView()获取开屏广告的view 。
Get the view of the splash ad
onFinished()当执行完缩放动画时,开发者必须调用此方法通知SDK,显示广告的关闭按钮 。
When the zoom animation is finished, the developer must call this method to notify the SDK and display the ad's close button.
destroy()当广告关闭不再使用时,必须调用此方法释放资源。
When the ad is closed and no longer used, this method must be called to release resources.

1.5 WMSplashEyeAdListener

  • com.windmill.sdk.splash.WMSplashEyeAdListener
方法名
Method
方法介绍
Method Introduction
onAnimationStart(View splashView)开发者需在此回调中执行开屏点睛广告的动画缩放
splashView:开屏广告的View
注意:
(1)缩放动画的示例代码可参考Demo。
(2)缩放动画结束时,必须调用IWMSplashEyeAd#onFinished()
(3)快手不会触发此回调,不能控制快手的缩放动画
Developers need to execute the animation scaling of the splash screen ad in this callback.】
splashView: View of the splash screen ad.
Note:
(1) For the sample code of the scaling animation, refer to the Demo.
(2) When the scaling animation ends, IWMSplashEyeAd#onFinished() must be called .
(3) Kuaishou will not trigger this callback and cannot control the scaling animation of Kuaishou .
onAdDismiss(boolean isSupportEyeSplash)开屏点睛广告关闭回调,建议在回调中调用IWMSplashEyeAd#destroy()
isSupportEyeSplash:是否支持开屏点睛 。
The callback for closing the eye-splash ad. It is recommended to call IWMSplashEyeAd#destroy()
in the callback . isSupportEyeSplash: whether the eye-splash ad is supported.

2. 接入代码示例
Code example

2.1 普通开屏广告接入事例
Examples of Common Splash Ads

2.1.1 设置监听回调
Setting the listener callback

java
WMSplashAdListener splashAdListener = new WMSplashAdListener() {
    @Override
    public void onSplashAdSuccessPresent(AdInfo adInfo) {// 开屏广告成功展示

    }

    /**
     *  开屏广告成功加载
     *  如果不是LoadAndShow模式,则需要调用showAd()方法展示广告
     *  adContainer 开屏内容展示容器,若传null,则默认进行全屏展示
     */
    @Override
    public void onSplashAdSuccessLoad(String placementId) {

    }

    /**
     * 开屏广告展示失败
     * WindAdError 开屏广告错误内容
     * placementId 广告位
     * 广告失败直接进入主页面
     */
    @Override
    public void onSplashAdFailToLoad(WindMillError error, String placementId) {
        jumpMainActivity();
    }

    @Override
    public void onSplashAdClicked(AdInfo adInfo) {

    }

    @Override
    public void onSplashClosed(AdInfo adInfo, IWMSplashEyeAd splashEyeAd) {// 开屏广告关闭
        //需要判断是否能进入主页面
        jumpWhenCanClick();
    }
};

2.1.2 开屏广告点击注意事项
Things to note when clicking on splash ads

java
/**
 * 设置一个变量来控制当前开屏页面是否可以跳转,当开屏广告为普链类广告时,点击会打开一个广告落地页,此时开发者还不能打开自己的App主页。
 * 当从广告落地页返回以后,才可以跳转到开发者自己的App主页;当开屏广告是App类广告时只会下载App。
 */
public boolean canJumpImmediately = false;

private void jumpWhenCanClick() {
    if (canJumpImmediately) {
        jumpMainActivity();
    } else {
        canJumpImmediately = true;
    }
}

/**
 * 不可点击的开屏,使用该jump方法,而不是用jumpWhenCanClick
 */
private void jumpMainActivity() {
    Intent intent = new Intent(this, MainActivity.class);
    this.startActivity(intent);
    this.finish();
}

@Override
protected void onPause() {
    canJumpImmediately = false;
}

@Override
protected void onResume() {
    if (canJumpImmediately) {
        jumpWhenCanClick();
    }
    canJumpImmediately = true;
}

2.1.3 开屏加载展示
Splash ads loading display

此方式自适应广告展示大小,自带LOGO样式展示APP信息,无需开发者处理底部LOGO内容

This method is adaptive to the display size of the advertisement, and has its own LOGO style to display the APP information, without the need for developers to process the bottom LOGO content

java
/**
 * PLACEMENT_ID 必填
 * USER_ID 可选
 * OPTIONS 自定义参数
 * options.put(WMConstants.AD_WIDTH, widthPixels)//单位px
 * options.put(WMConstants.AD_HEIGHT, heightPixels)//单位px
 */
 
//请求广告时可以传入期望的宽高
Map<String, Object> options = new HashMap<>();
options.put(WMConstants.AD_WIDTH, widthPixels);//单位px
options.put(WMConstants.AD_HEIGHT,heightPixels);//单位px
 
WMSplashAdRequest adRequest = new WMSplashAdRequest(PLACEMENT_ID, USER_ID, options);

/**
 * 广告结束,广告内容是否自动隐藏.默认是false
 * 若开屏和应用共用Activity,建议false。
 * 若开屏是单独Activity ,建议true。
 */
adRequest.setDisableAutoHideAd(true);

/**
 * 设置开屏应用LOGO区域(可选)
 * 设置此项开屏会默认使用Window渲染
 */
adRequest.setAppTitle(appTitle);

//设置开屏应用LOGO描述(可选)
adRequest.setAppDesc(appDesc);

WMSplashAd mWindSplashAD = new WMSplashAd(activity, adRequest, splashAdListener);

/**
 * 建议默认实时加载并展示广告
 */
private boolean isLoadAndShow = true;

/**
 * adContainer 开屏内容展示容器,若传null,则默认进行全屏展示
 */
if (isLoadAndShow) {
    mWindSplashAD.loadAdAndShow(adContainer);//不需要再调用mWindSplashAD.showAd();
} else {
    mWindSplashAD.loadAdOnly();//需要在onSplashAdSuccessLoad回调里调用mWindSplashAD.showAd();
}

2.2 开屏点睛事例
Examples of splash ads V+

2.2.1 开屏Activity与显示点睛广告的Activity不是同一个
The splash ads activity is different from the activity that displays the splash ads V+

1、新建SplashEyeAdHolder类用于缓存IWMSplashEyeAd实例

A new SplashEyeAdHolder class is created to cache the IWMSplashEyeAd instance

java
public class SplashEyeAdHolder {
    public static IWMSplashEyeAd splashEyeAd;
}

2、onSplashClosed时缓存splashEyeAd对象并设置开屏相关信息

Cache splashEyeAd object and set screen opening related information when onSplashClosed

java
public class SplashActivity extends AppCompatActivity implements WMSplashAdListener {
    /**
     * 设置开屏相关信息(SplashZoomOutManager请参考Demo),同时跳转首页Activity并取消页面跳转动画,关闭当前页面
     */
    private void jumpMainActivity() {
        if (SplashEyeAdHolder.splashEyeAd != null) {
            try {
                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(getApplicationContext());
                zoomOutManager.setSplashInfo(SplashEyeAdHolder.splashEyeAd.getSplashView(), getWindow().getDecorView());
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        overridePendingTransition(0, 0);
        this.finish();
    }

    @Override
    public void onSplashClosed(AdInfo adInfo, IWMSplashEyeAd splashEyeAd) {
        SplashEyeAdHolder.splashEyeAd = splashEyeAd;
        jumpMainActivity();
    }
}

3、在首页Activity中,创建showSplashEyeAd()方法

In the home page Activity, create the showSplashEyeAd() method

java
public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        showSplashEyeAd();

    }
    
    private View zoomOutView;
    
    private void showSplashEyeAd() {

        if (SplashEyeAdHolder.splashEyeAd == null) {
            return;
        }

        SplashEyeAdHolder.splashEyeAd.show(MainActivity.this, null, new WMSplashEyeAdListener() {
            @Override
            public void onAnimationStart(View splashView) {
                Log.i(TAG, "------------onAnimationStart---------");
                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(getApplicationContext());

                int[] suggestedSize = SplashEyeAdHolder.splashEyeAd.getSuggestedSize(getApplicationContext());
                if (suggestedSize != null) {
                    zoomOutManager.setSplashEyeAdViewSize(suggestedSize[0], suggestedSize[1]);
                }
                zoomOutView = zoomOutManager.startZoomOutInTwoActivity((ViewGroup) getWindow().getDecorView(),
                        findViewById(android.R.id.content), new SplashZoomOutManager.AnimationCallBack() {

                            @Override
                            public void animationStart(int animationTime) {
                                Log.i(TAG, "------------animationStart---------");
                            }

                            @Override
                            public void animationEnd() {
                                Log.i(TAG, "------------animationEnd---------");
                                SplashEyeAdHolder.splashEyeAd.onFinished();
                            }
                        });

                if (zoomOutView != null) {
                    overridePendingTransition(0, 0);
                }
            }

            @Override
            public void onAdDismiss(boolean isSupportEyeSplash) {
                Log.i(TAG, "------------onAdDismiss---------" + isSupportEyeSplash);
                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(getApplicationContext());
                zoomOutManager.clearStaticData();
                if (zoomOutView != null) {
                    ViewUtils.removeFromParent(zoomOutView);
                }
                SplashEyeAdHolder.splashEyeAd.destroy();
                SplashEyeAdHolder.splashEyeAd = null;
            }
        });
    }
}

2.2.2 开屏Activity与显示点睛广告的Activity是同一个
The Splash ads activity and the activity that displays the Splash ad V+ are the same

java
public class MainActivity extends AppCompatActivity {

    String splash_placement_id = "";
    private WMSplashAd splashAd;
    private ViewGroup splashLY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViewGroup(this);

        WMSplashAdRequest adRequest = new WMSplashAdRequest(splash_placement_id, String.valueOf(0), null);
        splashAd = new WMSplashAd(this, adRequest, new WMSplashAdListener() {
            @Override
            public void onSplashAdSuccessPresent(AdInfo adInfo) {
                Log.d("lance", "------onSplashAdSuccessPresent-------");
            }

            @Override
            public void onSplashAdSuccessLoad(String placementId) {
                Log.d("lance", "------onSplashAdSuccessLoad-------");
            }

            @Override
            public void onSplashAdFailToLoad(WindMillError error, String placementId) {
                Log.d("lance", "------onSplashAdFailToLoad-------" + error.toString());
                if (splashLY != null) {
                    splashLY.removeAllViews();
                    splashLY.setVisibility(View.GONE);
                }
            }

            @Override
            public void onSplashAdClicked(AdInfo adInfo) {
                Log.d("lance", "------onSplashAdClicked-------");
            }

            @Override
            public void onSplashClosed(AdInfo adInfo, IWMSplashEyeAd splashEyeAd) {
                Log.d("lance", "------onSplashClosed-------");
                if (splashLY != null) {
                    splashLY.removeAllViews();
                    splashLY.setVisibility(View.GONE);
                }
                //展示点睛广告
                showSplashEyeAd(splashEyeAd);
            }
        });

//        splashAd.loadAdAndShow(null);
        splashAd.loadAdAndShow(splashLY);
    }

    private void initViewGroup(Activity activity) {

        splashLY = new RelativeLayout(activity);

        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

        ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();

        viewGroup.addView(splashLY, layoutParams);
    }

		private View zoomOutView;
		
    private void showSplashEyeAd(IWMSplashEyeAd splashEyeAd) {
        if (splashEyeAd == null) {
            return;
        }
        splashEyeAd.show(this, null, new WMSplashEyeAdListener() {
            @Override
            public void onAnimationStart(View splashView) {
                Log.i("lance", "----------onAnimationStart---------: eye ad");
                //执行缩放动画
                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(MainActivity.this.getApplicationContext());

                ////建议优先使用IATSplashEyeAd#getSuggestedSize()返回的大小作为缩放动画的目标大小
                int[] suggestedSize = splashEyeAd.getSuggestedSize(MainActivity.this.getApplicationContext());
                if (suggestedSize != null) {
                    zoomOutManager.setSplashEyeAdViewSize(suggestedSize[0], suggestedSize[1]);
                }

//                zoomOutManager.setSplashInfo(splashView, getMyActivity().getWindow().getDecorView());
                ViewGroup content = MainActivity.this.findViewById(android.R.id.content);
                zoomOutView = zoomOutManager.startZoomOut(splashView, content, content, new SplashZoomOutManager.AnimationCallBack() {

                    @Override
                    public void animationStart(int animationTime) {
                        Log.i("lance", "----------animationStart---------: eye ad");
                    }

                    @Override
                    public void animationEnd() {
                        Log.i("lance", "----------animationEnd---------: eye ad");
                        //当缩放动画完成时必须调用IATSplashEyeAd#onFinished()通知SDK
                        splashEyeAd.onFinished();
                    }
                });
            }

            @Override
            public void onAdDismiss(boolean isSupportEyeSplash) {
                Log.i("lance", "----------onAdDismiss---------:" + isSupportEyeSplash);
                //建议在此回调中调用IATSplashEyeAd#destroy()释放资源以及释放其他资源,以免造成内存泄漏
                SplashZoomOutManager zoomOutManager = SplashZoomOutManager.getInstance(MainActivity.this.getApplicationContext());
                zoomOutManager.clearStaticData();
                if (zoomOutView != null) {
                    ViewUtils.removeFromParent(zoomOutView);
                }
                splashEyeAd.destroy();
            }
        });
    }
}