目录

1. 使用场景

广告主APP开发者也可直接调用Ads Kit的AIDL接口获取华为设备上的转化跟踪参数,这种集成方式不需要集成任何华为SDK。AIDL接口获取到的转化跟踪参数与同一台设备上SDK接口获取到的转化跟踪参数相同。

2. 调用流程

3. 开发步骤

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


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

  1. package com.huawei.android.hms.ppskit;
  2. /** 重要:请不要修改此AIDL文件的方法顺序 */
  3. interface IPPSChannelInfoService {
  4.   String getChannelInfo();
  5. }


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

步骤1 实现ServiceConnection的onServiceConnected方法。

步骤2 调用Android原生的IPPSChannelInfoService.Stub.asInterface方法获取IPPSChannelInfoService。

步骤3 调用getChannelInfo方法获取转化跟踪参数。

  1. private final class InstallReferrerServiceConnection implements ServiceConnection {
  2.        private InstallReferrerServiceConnection() {
  3.        }
  4.        @Override
  5.        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  6.            Log.i(TAG, "onServiceConnected");
  7.            IPPSChannelInfoService service = IPPSChannelInfoService.Stub.asInterface(iBinder);
  8.            if (null != service) {
  9.                try {
  10.                    String json = service.getChannelInfo();
  11.                    parseChannelJson(json);
  12.                } catch (RemoteException e) {
  13.                    Log.e(TAG, "getChannelInfo Excepition");
  14.                } finally {
  15.                    mContext.unbindService(this);
  16.                }
  17.            }
  18.        }
  19.        @Override
  20.        public void onServiceDisconnected(ComponentName componentName) {
  21.            Log.i(TAG, "onServiceDisconnected");
  22.        }
  23.    }
  24. }


4. 连接转化跟踪参数的AIDL服务。

步骤1 创建一个InstallReferrerServiceConnection实例。

步骤2 创建一个Intent,Action是“com.huawei.android.hms.CHANNEL_SERVICE”。

步骤3 设置Intent的包名为”com.huawei.hwid”。

步骤4 调用bindService连接转化跟踪参数的AIDL服务。

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


5. 解析返回的JSON格式写转化跟踪参数。

  1. private ReferrerDetails parseChannelJson(String channelJson) {
  2.    Log.i(TAG, "parseChannelJson: " + channelJson);
  3.    try {
  4.        JSONObject jsonObject = new JSONObject(channelJson);
  5.        String channelInfo = jsonObject.optString("channelInfo");
  6.        long installTimestamp = jsonObject.optLong("installTimestamp", 0);
  7.        long clickTimestamp = jsonObject.optLong("clickTimestamp", 0);
  8.        ReferrerDetails referrerDetails = new ReferrerDetails(channelInfo, clickTimestamp, installTimestamp);
  9.        updateReferrerDetails(referrerDetails);
  10.        return referrerDetails;
  11.    } catch (JSONException e) {
  12.        Log.e(TAG, "");
  13.    }
  14.    return null;
  15. }