文档管理中心
我的

此版本文档已归档不再维护,推荐您使用最新版本。

指南广告服务流量变现服务应用开发广告形式极速开屏

极速开屏

极速开屏服务由HUAWEI Ads推出,在提升用户开屏体验的同时为开发者提供全新的广告变现方案,开发者无需集成SDK即可全版本接入极速开屏服务。

前提条件

  • 当前仅中国区域支持。

  • HMS Core 4.0.3.300及以上版本。

  • EMUI 10.0.1.170及以上版的华为设备。

使用场景

接入了华为极速开屏的应用,在用户同意应用的用户协议之前,极速开屏不会展示。

当用户协议的同意状态发生变化时(用户同意或者撤销同意),需要将最新状态同步到Huawei Ads。

调用流程


开发步骤

用户协议同意状态同步至HUAWEI Ads

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

2. 将以下内容复制到AIDL文件中。

  1. package com.huawei.hms.ads;
  2. interface ExSplashService {
  3.    void enableUserInfo(boolean enable);
  4. }

3. 创建一个类,实现Android原生的ServiceConnection接口。

a. 实现ServiceConnection的onServiceConnected方法。

b. 调用Android原生的ExSplashService.Stub.asInterface方法获取ExSplashService。

c. 调用enableUserInfo方法同步用户协议状态。

  1. public final class ExSplashServiceConnection implements ServiceConnection {
  2.    private static final String TAG = "ExSplashServiceConnection";
  3.    private Context context;
  4.    public ExSplashServiceConnection(Context context) {
  5.        this.context = context;
  6.    }
  7.    @Override
  8.    public void onServiceConnected(ComponentName name, IBinder service) {
  9.        Log.i(TAG, "onServiceConnected");
  10.        ExSplashService exSplashService = ExSplashService.Stub.asInterface(service);
  11.        if (exSplashService != null) {
  12.            try {
  13.                // 同意为true,不同意为false
  14.                exSplashService.enableUserInfo(true);
  15.            } catch (RemoteException e) {
  16.                Log.i(TAG, "enableUserInfo error");
  17.            } finally {
  18.                context.unbindService(this);
  19.            }
  20.        }
  21.    }
  22.    @Override
  23.    public void onServiceDisconnected(ComponentName name) {
  24.        Log.i(TAG, "onServiceDisconnected");
  25.    }
  26. }

4. 连接极速开屏的AIDL服务。

a. 创建一个ExSplashServiceConnection实例。

b. 创建一个Intent,Action是“com.huawei.hms.ads.EXSPLASH_SERVICE”。

c. 设置Intent的包名为“com.huawei.hwid”。

d. 调用bindService连接极速开屏的AIDL服务。

  1. private boolean bindService(Context context) {
  2.    ExSplashServiceConnection serviceConnection = new ExSplashServiceConnection(context);
  3.    Intent intent = new Intent("com.huawei.hms.ads.EXSPLASH_SERVICE");
  4.    intent.setPackage("com.huawei.hwid");
  5.    boolean result = context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
  6.    Log.i(TAG, "bindService result: " + result);
  7.    return result;
  8. }

(可选)极速开屏广告广播通知

在极速开屏广告展示时,HUAWEI Ads会通过发送一个广播通知应用,广播的ACTION为“com.huawei.hms.ads.EXSPLASH_DISPLAYED”,应用可以注册一个广播接收器来接受此广播,并自行决策如何使用。

1. 创建广播接收器,实现一个继承BroadcastReceiver的类,并实现onReceive方法。

  1. public class ExSplashBroadcastReceiver extends BroadcastReceiver {
  2.    @Override
  3.    public void onReceive(Context context, Intent intent) {
  4.        if (intent == null) {
  5.            return;
  6.        }
  7.        String action = intent.getAction();
  8.        if (action.equals("com.huawei.hms.ads.EXSPLASH_DISPLAYED")) {
  9.            // do your stuff here.
  10.        }
  11.    }
  12. }

2. 注册广播,建议在应用启动时即注册。

  1. IntentFilter filter = new IntentFilter("com.huawei.hms.ads.EXSPLASH_DISPLAYED");
  2. registerReceiver(new ExSplashBroadcastReceiver(), filter);


本页面可能包含由第三方许可的内容,请参考具体描述。