Skip to main content

Initialize Android SDK

Once our SDK has been added to your project, you need to initialize it. The initialization process will run in a background thread and prepare the SDK for interactions with the user and your application.

SDK initialization requires a Configuration ID which is generated in Console. To learn how to obtain this, see ATS Mobile SDK.

How to Initialize ATS Android SDK

  1. Add permission to manifest.

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  2. Initialize the SDK. During this step, you will need to provide the Config ID you've previously obtained from Console. You can also use a Config ID that is linked to an unapproved ATS placement for testing purposes.

    Caution

    The ATS Mobile SDK only supports Kotlin v1.6.0 and above

    After the initialization process is complete, if the ATS placement tied to the Config ID is still not yet approved, the SDK will return fake data which should only be used for testing. Information regarding the placement status can be found in the log output of the SDK.

    Kotlin:

    LRAtsManager.initialize(LRAtsConfiguration("40b867f9-93cc-4687-a2c7-d02bed91aaee", false, false),
        object : LRCompletionHandlerCallback {
            override fun invoke(success: Boolean, error: LRError?) {
                if (success) {
                    // SDK ready for use
                } else {
                    // SDK failed to initialize
                }
        }
    })

    Java:

    LRAtsManager.INSTANCE.initialize(new LRAtsConfiguration("40b867f9-93cc-4687-a2c7-d02bed91aaee", false, false), new LRCompletionHandlerCallback() {
        @Override
        public void invoke(boolean success, @Nullable LRError lrError) {
            if (success) {
                // SDK ready for use
            } else {
                // SDK failed to initialize
            }
        }
    });

    Caution

    Since Java doesn’t support default parameter values, to successfully initialize SDK in Java projects you have to pass all the LRAtsConfiguration parameters.