文档管理中心

获取OAID信息(AIDL方式)

1. 使用场景

开发者也可直接调用Ads Kit的AIDL接口获取华为设备上的OAID,这种集成方式不需要集成任何华为SDK。AIDL接口获取到的OAID与同一台设备上SDK接口获取到的OAID相同。

2. 调用流程

3. 开发步骤

1.创建接口OpenDeviceIdentifierService的AIDL文件,放置在com.uodis.opendevice.aidl包路径下,如下图:

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

  1. package com.uodis.opendevice.aidl;
  2. /** 重要:请不要修改此AIDL文件的方法顺序 */
  3. interface OpenDeviceIdentifierService {
  4.    /** 获取OAID */
  5.    String getOaid();
  6.    /** 获取限制跟踪参数,true:限制跟踪;false:不限制跟踪*/
  7.   boolean isOaidTrackLimited();
  8. }

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

步骤1 实现ServiceConnection的onServiceConnected方法。

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

步骤3 调用getOaid和isOaidTrackLimited方法获取OAID和“限制个性化广告”开关。

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

4.连接OAID的AIDL服务。

步骤1 创建一个IdentifierServiceConnection实例。

步骤2 创建一个Intent,Action是“com.uodis.opendevice.OPENIDS_SERVICE”。

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

步骤4 调用bindService连接OAID的AIDL服务。

  1. private boolean bindService() {
  2.    IdentifierServiceConnection serviceConnection = new IdentifierServiceConnection();
  3.    Intent intent = new Intent("com.uodis.opendevice.OPENIDS_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. }
本页面可能包含由第三方许可的内容,请参考具体描述
搜索
请输入您想要搜索的关键词