At a glance: Collect the Android OAID using the AppsFlyer SDK to attribute installs from third-party Android app stores.
Collecting OAIDs
The AppsFlyer SDK supports OAID collection using several methods. The method depends on the following factors:
- Device model and OS
- AppsFlyer SDK version
Collection methods
The methods include setCollectOaid and setOaidData.
- setCollectOaid:
- For all devices, the AppsFlyer SDK collects the OAID directly from the device OS.
- For SDK
V5.4.0+
, once the OAID dependencies are added to the app, the SDK attempts to collect OAID automatically by default. - For earlier SDK versions, the method needs to be set manually.
- setOaidData: For when the developer wants to use AIDL to collect the OAID, and then pass the OAID to the AppsFlyer SDK.
setOaidData (AIDL)—developer passes the OAID
To collect the OAID in Huawei devices using AppsFlyer SDK version V5.2.0 and later:
-
Pass the OAID collected by Huawei to the AppsFlyer SDK.
-
Call
setOaidData()
before callingstartTracking()
. In the code call,AppsFlyerLib.getInstance().setOaidData(<OAID_HERE>);
Example:
This example demonstrates the setOaidData (AIDL) method for Huawei devices:
-
Create a folder,
aidl
. -
In the
aidl
folder, create a package with this exact name,com.uodis.opendevice.aidl
. -
Create an
.aidl
file,OpenDeviceIdentifierServiced
. -
Check that file
OpenDeviceIdentifierServiced
includes this code:package com.uodis.opendevice.aidl; /* * Important: Do not modify the method sequence of the AIDL file.!!! */ interface OpenDeviceIdentifierService { String getOaid(); boolean isOaidTrackLimited(); }
-
Create a class that fetches the OAID and passes it to the AppsFlyer SDK.
In this example, the class isOaidFetcher
.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); } }
Collect OAID (in China)
Select a collection method based on the SDK version. The developer must add the manufacturer's standalone JAR file to the app or add it to the AppsFlyer OAID SDK.
- Download the AAR provided by the MSA alliance to your module libs folder
- Add OAID dependencies; they must support the manufacturer's standalone JAR file in the app-level build.gradle file:
implementation 'com.appsflyer:af-android-sdk:6.1.3@aar'
implementation 'com.appsflyer:oaid:6.1.1'
implementation files('libs/oaid_sdk_1.0.23.aar')
To collect the OAID in AppsFlyer SDK version V5.4.0:
Once the OAID dependencies are added, OAID is collected automatically by default.
To collect the OAID in AppsFlyer SDK version V5.2.0 and V5.3.0:
Call setCollectOaid()
before calling startTracking()
.
In the code, call AppsFlyerLib.getInstance().setCollectOaid(true);
Collect OAID (outside China)
When releasing an app outside China, The MSA SDK is not needed. Instead, use the Huawei OAID SDK to collect the device OAID.
- Add the following to the project
build.gradle
file:allprojects { repositories { // ... maven { url 'https://developer.huawei.com/repo/' } } }
- Add OAID dependencies; they must support the manufacturer's standalone JAR file in the app-level build.gradle file:
implementation 'com.appsflyer:af-android-sdk:6.1.3@aar' implementation 'com.appsflyer:oaid:6.1.1' implementation 'com.huawei.hms:ads-identifier:3.4.28.313'
To collect the OAID in AppsFlyer SDK version V5.4.0:
OAID is collected automatically by default.
To collect the OAID in AppsFlyer SDK version V5.2.0 and V5.3.0:
Call setCollectOaid()
before calling startTracking()
.
In the code, call AppsFlyerLib.getInstance().setCollectOaid(true);
Opting out of OAID
To opt-out of collecting the OAID:
Call setCollectOaid(false)
before calling startTracking()
. In the code call, AppsFlyerLib.getInstance().setCollectOaid(false);
Additional information
Supported devices
- The data, below, was provided by the manufacturers and is for information purposes only.
- For the most updated list of supported devices
Supported manufacturer versions | |
---|---|
Huawei |
|
Xiaomi | MIUI 10.2 |
Vivo | FuntouchOS 9 |
OPPO | Color OS 7.0 |
Lenovo | ZUI 11.4 |
Samsung, Meizu, Nubia, ZTE, ASUS, OnePlus, Freeme OS, Ssui OS | Android 10 |