Getting started | Mobile SDK | 2GIS Documentation
Android SDK

Getting started

First you need to contact 2GIS technical support to get a new key. Be sure to specify the appId of the application for which the key will be generated. The resulting key file dgissdk.key needs to be added to assets.

To begin working with the SDK, call the initialize() method of DGis and specify the application context.

class Application : Application() {
    lateinit var sdkContext: Context

    override fun onCreate() {
        super.onCreate()

        sdkContext = DGis.initialize(
            this
        )
    }
}

Note that you cannot create more than one Context instance.

Additionally, you can specify logging settings (LogOptions) and HTTP client settings (HttpOptions) such as caching.

// Logging settings
val logOptions = LogOptions(
    LogLevel.VERBOSE
)

// HTTP client settings
val httpOptions = HttpOptions(
    useCache = false
)

// Consent to personal data processing
val dataCollectConsent = PersonalDataCollectionConsent.GRANTED

sdkContext = DGis.initialize(
    appContext = this,
    dataCollectConsent = dataCollectConsent,
    logOptions = logOptions,
    httpOptions = httpOptions
)

To override some SDK operation settings, a file in the format VendorConfig is used, which is passed during SDK initialization.

There are several ways to create an instance of the VendorConfig class:

  1. VendorConfigFromAsset - the file should be located in the assets directory of the application source code and you must specify the file name in the constructor.
  2. VendorConfigFromFile - the file should be located on the device file system and you must specify the absolute path to it.
  3. VendorConfigFromString - a string with the contents of the json file should be passed to the constructor.

The created VendorConfig instance is passed to the DGis.initialize() method with the vendorConfig parameter