Link up
This document covers how to integrate the DFINERY Android SDK into Android. Installing the DFINERY SDK provides event analytics, user profiles, and actions.
Before you start
Service Settings
You must check Android in the Data Source section on the Service Management/Service Information page of the DFINERY console.
Support Information
Minimum supported SDK: Android 4.4+ / API 19+
Target SDK: 33
Recently compiled Firebase Cloud Messaging version: 24.0.0
Installing the SDK
Adding dependencies
To apply the DFINERY SDK dependency in your app, complete the following steps:
1. Add mavenCentral
in repositories to fetch maven dependencies.
mavenCentral
in repositories to fetch maven dependencies.allprojects {
repositories {
mavenCentral()
}
}
2. Open the build.gradle
file inside the app's module directory.
build.gradle
file inside the app's module directory.3. Add SDK dependencies for the latest version of DFINERY SDK and required components to dependencies.
dependencies {
implementation 'com.google.android.gms:play-services-appset:16.0.2'
//Get the latest version from https://mvnrepository.com/artifact/com.igaworks.dfinery/android-sdk
implementation 'com.igaworks.dfinery:android-sdk:HERE_LATEST_VERSION'
}
SDK Initialization
Initialize
To initialize the DFINERY SDK in your app, complete the following steps:
1. Create an object that inherits Application. If an inherited object already exists, use that object.
public class BaseApplication extends Application
2. Override the onCreate() method in an object that inherits Application
@Override
public void onCreate() {
super.onCreate();
}
3. Write the following code in the onCreate() method.
The Service ID can be found in the path of the DFINERY Console.
Service Management/Service Information/Key Information/Service Key
Dfinery.getInstance().init(this, "SERVICE_KEY");
The following code snippet shows an example of when initialization is complete.
public class BaseApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
Dfinery.getInstance().init(this, "SERVICE_KEY");
}
}
4. Register the application written in AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name=".BaseApplication">
</application>
</manifest>
5. Add the required permissions to AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Set up your Google Advertising ID (optional)
To collect the Google Advertising ID, setGoogleAdvertisingId()
you must set it manually via the method.
1. Open the build.gradle
file inside your app's module directory.
build.gradle
file inside your app's module directory.2. Add the dependencies required to collect the advertising ID to dependencies.
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
}
3. Add the required permissions to AndroidManifest.xml.
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
4. Set the advertising ID via thesetGoogleAdvertisingId()
method.
setGoogleAdvertisingId()
method.The advertising ID collection logic should be run in a separate thread. The code snippet below creates a Thread and runs it, but you can use other methods (AsyncTask, coroutine, etc.) depending on your needs.
new Thread(new Runnable() {
@Override
public void run() {
try {
AdvertisingIdClient.Info idInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
DfineryProperties.setGoogleAdvertisingId(idInfo.getId(), idInfo.isLimitAdTrackingEnabled());
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
SDK Setup
You can set options such as enabling logs when initializing the SDK.
Activate log
Logging can be enabled using DfineryConfig, which applies the settings of DFINERY. DfineryConfig can init()
be applied by passing it as a parameter when calling a method, or res/values/dfinery.xml
can be set using.
setLogEnable(boolean enable)
The first argument,
enable
is a value that sets whether to display the log or not. The default value isfalse
.
You can set the BuildConfig.DEBUG
value to output logs only in debug mode and not output them during deployment.
DfineryConfig config = new DfineryConfig.Builder()
.setLogEnable(true)
.build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
Change the log level
Log levels can be set using DfineryConfig, which applies Dfinery's settings. DfineryConfig can be applied as a parameter when calling the init()
method, or set using res/values/dfinery.xml
.
setLogLevel(int logLevel)
The first argument,
logLevel
, is a value that sets the log display level. The default value isLog.ERROR(6)
.
DfineryConfig config = new DfineryConfig.Builder()
.setLogLevel(Log.DEBUG)
.build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
Complete
SDK installation and initialization is complete.
Last updated