合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
此版本文档已归档不再维护,推荐您使用最新版本。
极速开屏服务由HUAWEI Ads推出,在提升用户开屏体验的同时为开发者提供全新的广告变现方案,开发者无需集成SDK即可全版本接入极速开屏服务。
当前仅中国区域支持。
HMS Core 4.0.3.300及以上版本。
EMUI 10.0.1.170及以上版的华为设备。
接入了华为极速开屏的应用,在用户同意应用的用户协议之前,极速开屏不会展示。
当用户协议的同意状态发生变化时(用户同意或者撤销同意),需要将最新状态同步到Huawei Ads。

1. 创建接口ExSplashService的AIDL文件,放置在com.huawei.hms.ads包路径下,如下图:

2. 将以下内容复制到AIDL文件中。
- package com.huawei.hms.ads;
- interface ExSplashService {
- void enableUserInfo(boolean enable);
- }
3. 创建一个类,实现Android原生的ServiceConnection接口。
a. 实现ServiceConnection的onServiceConnected方法。
b. 调用Android原生的ExSplashService.Stub.asInterface方法获取ExSplashService。
c. 调用enableUserInfo方法同步用户协议状态。
- public final class ExSplashServiceConnection implements ServiceConnection {
- private static final String TAG = "ExSplashServiceConnection";
- private Context context;
- public ExSplashServiceConnection(Context context) {
- this.context = context;
- }
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- Log.i(TAG, "onServiceConnected");
- ExSplashService exSplashService = ExSplashService.Stub.asInterface(service);
- if (exSplashService != null) {
- try {
- // 同意为true,不同意为false
- exSplashService.enableUserInfo(true);
- } catch (RemoteException e) {
- Log.i(TAG, "enableUserInfo error");
- } finally {
- context.unbindService(this);
- }
- }
- }
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.i(TAG, "onServiceDisconnected");
- }
- }
4. 连接极速开屏的AIDL服务。
a. 创建一个ExSplashServiceConnection实例。
b. 创建一个Intent,Action是“com.huawei.hms.ads.EXSPLASH_SERVICE”。
c. 设置Intent的包名为“com.huawei.hwid”。
d. 调用bindService连接极速开屏的AIDL服务。
- private boolean bindService(Context context) {
- ExSplashServiceConnection serviceConnection = new ExSplashServiceConnection(context);
- Intent intent = new Intent("com.huawei.hms.ads.EXSPLASH_SERVICE");
- intent.setPackage("com.huawei.hwid");
- boolean result = context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
- Log.i(TAG, "bindService result: " + result);
- return result;
- }
在极速开屏广告展示时,HUAWEI Ads会通过发送一个广播通知应用,广播的ACTION为“com.huawei.hms.ads.EXSPLASH_DISPLAYED”,应用可以注册一个广播接收器来接受此广播,并自行决策如何使用。
1. 创建广播接收器,实现一个继承BroadcastReceiver的类,并实现onReceive方法。
- public class ExSplashBroadcastReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent == null) {
- return;
- }
- String action = intent.getAction();
- if (action.equals("com.huawei.hms.ads.EXSPLASH_DISPLAYED")) {
- // do your stuff here.
- }
- }
- }
2. 注册广播,建议在应用启动时即注册。
- IntentFilter filter = new IntentFilter("com.huawei.hms.ads.EXSPLASH_DISPLAYED");
- registerReceiver(new ExSplashBroadcastReceiver(), filter);