Skip to content

SDK Initialization

This document covers the content related to Android SDK initialization.

Application Configuration

The optimal location for SDK initialization is within 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
        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
        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, must be configured together with datawayUrl.
setDebug Boolean No Whether to enable debug mode. Default is false. SDK runtime logs can be printed only after enabling.
setEnv EnvType No Sets the collection environment. Default is EnvType.PROD.
setEnv String No Sets 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 is needed in other processes.
setEnableAccessAndroidID Boolean No Enables obtaining Android ID. Default is true. Set to false, then the device_uuid field data will not be collected. For market privacy audit related information, view here.
addGlobalContext Dictionary No Adds SDK global attributes. For addition rules, please refer to here.
setServiceName String No Sets 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 Sets the number of entries for synchronization requests. SyncPageSize.MINI 5 entries, SyncPageSize.MEDIUM 10 entries, SyncPageSize.LARGE 50 entries. Default is SyncPageSize.MEDIUM.
setCustomSyncPageSize Enum No Sets the number of entries for synchronization requests. Range [5,). Note that a larger number of request entries means data synchronization occupies more computing resources. Default is 10. Note: Only one configuration is needed between setSyncPageSize and setCustomSyncPageSize.
setSyncSleepTime Int No Sets the synchronization interval time. Range [0,5000], unit ms. Default is 0.
enableDataIntegerCompatible Void No Recommended to enable when coexistence with web data is needed. 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 cached data from ft-sdk versions below 1.6.0. Default is false.
setCompressIntakeRequests Boolean No Compresses upload synchronization data with deflate. Enabled by default. Set to false to disable. Supported in ft-sdk version 1.6.3 and above.
enableLimitWithDbSize Void No Enables limiting data size using db. Default is 100MB, unit Byte. Larger set values 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 adds a unique ResourceID to Okhttp Request, used for high-concurrency scenarios with the same request. Supported in ft-sdk version 1.6.10 and above, ft-plugin version 1.3.5 and above.
setProxy java.net.Proxy No Sets Proxy proxy for data network synchronization requests. Only supports okhttp3. Supported in ft-sdk version 1.6.10 and above.
setProxyAuthenticator okhttp3.Authenticator No Sets Proxy 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 processing. Only supports okhttp3. Supported in ft-sdk version 1.6.10 and above.
setDataModifier DataModifier No Modifies a single field. Supported in ft-sdk version 1.6.11 and above. For usage examples, see here.
setLineDataModifier LineDataModifier No Modifies a single piece of data. 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 Sets 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

Shutting Down the SDK

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

FTSdk.shutDown();
FTSdk.shutDown()

Clearing SDK Cached Data

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

FTSdk.clearAllData();
FTSdk.clearAllData()

Manually Synchronizing Data

Use FTSdk to manually synchronize data.

FTSdk.setAutoSync(false) is required only when you need to manage data synchronization yourself.

FTSdk.flushSyncData();
FTSdk.flushSyncData()