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
2. Open the build.gradle file inside the app's module directory.
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'
}
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
class BaseApplication: Application()
@Override
public void onCreate() {
super.onCreate();
}
override fun onCreate() {
super.onCreate()
}
3. Write the following code in the onCreate() method.
Dfinery.getInstance().init(this, "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");
}
}
class BaseApplication: Application(){
override fun onCreate() {
super.onCreate()
Dfinery.getInstance().init(this, "SERVICE_KEY")
}
}
4. Register the application written in AndroidManifest.xml.
4. Set the advertising ID via thesetGoogleAdvertisingId() 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.
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.xmlcan be set using.
setLogEnable(boolean enable)
The first argument, enableis a value that sets whether to display the log or not. The default value is false.
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);
val config = DfineryConfig.Builder()
.setLogEnable(true)
.build()
Dfinery.getInstance().init(this, "SERVICE_KEY", config)
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 is Log.ERROR(6).
DfineryConfig config = new DfineryConfig.Builder()
.setLogLevel(Log.DEBUG)
.build();
Dfinery.getInstance().init(this, "SERVICE_KEY", config);
val config = DfineryConfig.Builder()
.setLogLevel(Log.DEBUG)
.build()
Dfinery.getInstance().init(this, "SERVICE_KEY", config)