Getting started | Mobile SDK | Urbi Documentation
Android SDK

Getting started

  1. Contact 2GIS technical support to get an access key. Be sure to specify the appId of the application for which the key will be generated.

  2. Add the received key file dgissdk.key to assets.

  3. 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
            )
        }
    }
    

    Important

    Context can be created in a single instance only.

  4. 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
    )
    

Object of the LogOptions class allows you not only to configure the logging level but also to specify a custom log sink using the customSink parameter. LogSink is an interface with a single write method that must be implemented.

Implementation of sending logs to Firebase Crashlytics can look as follows:

class FirebaseLogSink : LogSink {
    override fun write(message: LogMessage) {
        FirebaseCrashlytics.getInstance().log(message.text)
    }
}

Pass an instance of this class to the initialize() method of the DGis object:

sdkContext = DGis.initialize(
            ...
            logOptions = LogOptions(
                ...
                customSink = FirebaseLogSink()
            )
            ...
        )

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:

  • 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.
  • VendorConfigFromFile - the file should be located on the device file system and you must specify the absolute path to it.
  • 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.

Mobile SDK (the Full version) allows you to work with map, directory, and routing data offline from preloaded packages. This can be helpful when the network connection is low or missing.

To configure the offline mode:

  1. Ensure that your access key contains proper rights for working with offline data. You can request access to offline data for all components (map, directory, routing) or select only the required ones.

  2. Use TerritoryManager to download data files for territories where your application must work offline.

    See a code example of loading territories.

  3. Configure SDK components for working with preloaded data: