概览: 本文将介绍在AppsFlyer的SDK中收集设备标识符OAID的方法。
收集OAID
AppsFlyer的SDK中支持多种OAID的收集方法, 使用哪种方法取决于以下因素:
- 设备型号 与操作系统版本
- AppsFlyer SDK 版本
收集方法包括 setCollectOaid 与 setOaidData。
收集方法
方法包括 setCollectOaid 和 setOaidData
-
setCollectOaid:
- 对于所有设备, AppsFlyer SDK将会直接通过设备OS收集OAID。
- 从SDK V5.4.0版本开始, AppsFlyer SDK将默认尝试自动收集OAID
- 对于较早的SDK版本,这个方法需要手动设置
- setOaidData:适用于开发者希望用AIDL去 收集OAID,然后 将OAID传给AppsFlyer SDK的情况。
setOaidData (AIDL)—开发者收集OAID并上报给AppsFlyer
使用AppsFlyer SDK V5.2.0及以上版本,在华为设备中收集OAID:
-
将华为收集到的OAID传给AppsFlyer SDK。
-
Call
setOaidData()
before callingstartTracking()
. In the code call,
AppsFlyerLib.getInstance().setOaidData(###OAID_HERE###);
示例:
下列示例将展示在华为设备中如何使用 setOaidData (AIDL)方法:
-
创建一个文件夹,
aidl
。 -
在
aidl
文件夹中,创建一个名为com.uodis.opendevice.aidl
的包。 -
创建一个
.aidl
文件, OpenDeviceIdentifierServiced。
-
确认在文件
OpenDeviceIdentifierServiced
中包含以下代码:package com.uodis.opendevice.aidl; /* *Important: Do not modify the method sequence of the AIDL file.!!! */ interface OpenDeviceIdentifierService { String getOaid(); boolean isOaidTrackLimited(); }
-
创建一个获取 OAID 并且将其 传给AppsFlyer SDK的class。
在此示例中,class是OaidFetcher
。public class OaidFetcher { public static void connect(Context context) { ServiceConnection connection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { OpenDeviceIdentifierService oaidService = OpenDeviceIdentifierService.Stub.asInterface(service); try { String oaid = oaidService.getOaid(); AppsFlyerLib.getInstance().setOaidData(oaid); } catch (RemoteException e) { } } @Override public void onServiceDisconnected(ComponentName name) { } }; Intent bindIntent = new Intent("com.uodis.opendevice.OPENIDS_SERVICE"); bindIntent.setPackage("com.huawei.hwid"); context.bindService(bindIntent, connection, context.BIND_AUTO_CREATE); } }
setCollectOaid—通过AppsFlyer SDK收集OAID
基于SDK版本选择对应的上报方法,开发者必须要将厂商的独立JAR文件添加在app,或将其添加到AppsFlyer的OAID SDK。
- 将 MSA移动安全联盟提供的 AAR下载到您的module libs文件夹中
-
添加OAID dependencies,必须在app层级build.gradle文件夹中支持厂商的独立JAR文件:
implementation 'com.appsflyer:af-android-sdk:5.1.0@aar'
implementation 'com.appsflyer:oaid:6.1.1'
implementation files('libs/oaid_sdk_1.0.23.aar')
使用V5.4.0+ AppsFlyer SDK收集OAID:
SDK默认自动收集OAID。(前提是完成上述步骤)
使用AppsFlyer SDK V5.2.0或V5.3.0收集OAID:
在 startTracking()
之前调用 setCollectOaid()
具体代码参考 AppsFlyerLib.getInstance().setCollectOaid(true);
选择退出(opt-out)收集OAID:
在调用startTracking()
之前调用 setCollectOaid(false)
, 在代码中调用
AppsFlyerLib.getInstance().setCollectOaid(false);
附加信息
支持设备
- 以下数据由制造厂商提供,仅供参考使用
- 最新支持设备列表
支持的制造商版本 | |
---|---|
华为 |
|
小米 | MIUI 10.2 |
Vivo | FuntouchOS 9 |
OPPO | Color OS 7.0 |
联想 | ZUI 11.4 |
Samsung, Meizu, Nubia, ZTE, ASUS, OnePlus, Freeme OS, Ssui OS | Android 10 |