Skip to content

SDK Initialization

This article covers the content related to Android SDK initialization.

Application Configuration

The optimal location for SDK initialization is in the onCreate method of the Application. If your application has not yet created an Application, you need to create one and declare it in AndroidManifest.xml. For an example, please refer to here.

<application
       android:name="YourApplication">
</application>

Basic Configuration

public class DemoApplication extends Application {

    @Override
    public void onCreate() {
        // Local environment deployment, Datakit deployment
        FTSDKConfig config = FTSDKConfig.builder(datakitUrl);
        // Using public network DataWay
        FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken);
        // ...
        // config.setDebug(true);              // debug mode
        config.setCompressIntakeRequests(true); // Compress intake requests
        FTSdk.install(config);
    }
}
class DemoApplication : Application() {
    override fun onCreate() {
        // Local environment deployment, Datakit deployment
        val config = FTSDKConfig.builder(datakitUrl)
        // Using public network DataWay
        val config = FTSDKConfig.builder(datawayUrl, clientToken)
        // ...
        // config.setDebug(true)              // debug mode
        config.setCompressIntakeRequests(true) // Compress intake requests
        FTSdk.install(config)
    }
}
Method Name Type Required Meaning
datakitUrl String Yes The reporting URL address for local environment deployment (Datakit). Example: http://10.0.0.1:9529, default port is 9529. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration.
datawayUrl String Yes The reporting URL address for public network Dataway. Obtain it from the [RUM] application. Example: https://open.dataway.url. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration.
clientToken String Yes Authentication token, needs to be configured together with datawayUrl.
setDebug Boolean No Whether to enable debug mode. Default is false. SDK runtime logs can be printed after enabling.
setEnv EnvType No Set the collection environment. Default is EnvType.PROD.
setEnv String No Set the collection environment. Default is prod. Note: Only one configuration is needed for either String or EnvType type.
setOnlySupportMainProcess Boolean No Whether to support running only in the main process. Default is true. Set this field to false if execution in other processes is required.
setEnableAccessAndroidID Boolean No Enable obtaining Android ID. Default is true. Set to false to stop collecting data for the device_uuid field. For market privacy audit related information, view here.
addGlobalContext Dictionary No Add SDK global attributes. For addition rules, please refer to here.
setServiceName String No Set the service name, affecting the service field data in Log and RUM. Default is df_rum_android.
setAutoSync Boolean No Whether to automatically synchronize data to the server after collection. Default is true. When false, use FTSdk.flushSyncData() to manage data synchronization manually.
setSyncPageSize Int No Set the number of entries per synchronization request. SyncPageSize.MINI 5 entries, SyncPageSize.MEDIUM 10 entries, SyncPageSize.LARGE 50 entries. Default is SyncPageSize.MEDIUM.
setCustomSyncPageSize Enum No Set the number of entries per synchronization request. Range [5,). Note that a larger number of entries means data synchronization consumes more computing resources. Default is 10. Note: Only one configuration is needed between setSyncPageSize and setCustomSyncPageSize.
setSyncSleepTime Int No Set the synchronization interval time. Range [0,5000], unit ms. Default is 0.
enableDataIntegerCompatible Void No Recommended to enable when coexistence with web data is required. This configuration handles web data type storage compatibility issues. Enabled by default in ft-sdk version 1.6.9.
setNeedTransformOldCache Boolean No Whether compatibility is needed to synchronize old cache data from ft-sdk versions below 1.6.0. Default is false.
setCompressIntakeRequests Boolean No Compress upload synchronization data using deflate. Disabled by default. Supported in ft-sdk version 1.6.3 and above.
enableLimitWithDbSize Void No Enable limiting data size using db. Default 100MB, unit Byte. Larger settings increase disk pressure. Not enabled by default. After enabling, FTLoggerConfig.setLogCacheLimitCount and FTRUMConfig.setRumCacheLimitCount will become invalid. Supported in ft-sdk version 1.6.6 and above.
setEnableOkhttpRequestTag Boolean No Automatically add a unique ResourceID to Okhttp Requests, used for high-concurrency scenarios with identical requests. Supported in ft-sdk 1.6.10+ and ft-plugin 1.3.5+.
setProxy java.net.Proxy No Set Proxy for data network synchronization requests. Only supports okhttp3. Supported in ft-sdk version 1.6.10 and above.
setProxyAuthenticator okhttp3.Authenticator No Set Proxy for data synchronization network requests. Only supports okhttp3. Supported in ft-sdk version 1.6.10 and above.
setDns okhttp3.Dns No Data synchronization network requests support custom Dns for custom domain name resolution. Only supports okhttp3. Supported in ft-sdk version 1.6.10 and above.
setDataModifier DataModifier No Modify individual fields. Supported in ft-sdk version 1.6.11 and above. For usage examples, see here.
setLineDataModifier LineDataModifier No Modify single data entries. Supported in ft-sdk version 1.6.11 and above. For usage examples, see here.
setRemoteConfiguration Boolean No Whether to enable the remote configuration function for data collection. Default is false. After enabling, SDK initialization or application hot start will trigger data updates. Supported in ft-sdk version 1.6.12 and above. DataKit version requirement >= 1.60 or using public network Dataway.
setRemoteConfigMiniUpdateInterval Int No Set the minimum update interval for data, unit seconds. Default is 12 hours. Supported in ft-sdk version 1.6.12 and above.
setRemoteConfigurationCallBack FTRemoteConfigManager.FetchResult No Remote configuration result callback. Code example. Supported in ft-sdk version 1.6.16 and above.

Runtime Capabilities

Shut Down SDK

If dynamically changing SDK configuration, shut it down first to avoid generating erroneous data.

FTSdk.shutDown();
FTSdk.shutDown()

Clear SDK Cache Data

Use FTSdk to clear cached data that has not been reported.

FTSdk.clearAllData();
FTSdk.clearAllData()

Actively Synchronize Data

Use FTSdk to actively synchronize data.

Only required when FTSdk.setAutoSync(false) is set, to manage data synchronization manually.

FTSdk.flushSyncData();
FTSdk.flushSyncData()