MainActivity

Overview

The MainActivity serves as the entry point for the MultiSet SDK demo application. It demonstrates SDK initialization, authentication handling, and navigation to the AR localization activity.

Description

This activity is responsible for:

  1. Initializing the MultiSet SDK with credentials

  2. Handling the authentication flow

  3. Managing camera and ARCore permissions

  4. Launching the unified MultiSetLocalizationActivity for single-frame or multi-frame localization


Authentication Flow

1. SDK Initialization

The SDK is initialized using credentials from BuildConfig:

val config = MultiSetConfig.Builder(clientId, clientSecret)
    .mapCode(mapCode)           // or .mapSetCode(mapSetCode)
    .enableMeshVisualization(true)
    .backgroundLocalization(true)
    .build()

MultiSetSDK.initialize(this, config, this)

2. Configuration Builder Options

Method
Description

mapCode(String)

Set a single map code for localization

mapSetCode(String)

Set a map set code for localizing against multiple maps

enableMeshVisualization(Boolean)

Enable/disable 3D mesh overlay visualization

backgroundLocalization(Boolean)

Enable/disable background localization

3. Authentication Callbacks

The activity implements MultiSetCallback to receive authentication events:


APIs Used for Authentication

MultiSetSDK

Method
Description

MultiSetSDK.initialize(context, config, callback)

Initializes the SDK with configuration and callback

MultiSetSDK.getLastLocalizationResult()

Returns the last successful LocalizationResult, or null

MultiSetConfig.Builder

Method
Parameters
Description

Builder(clientId, clientSecret)

String, String

Creates a configuration builder with credentials

mapCode(code)

String

Sets the map code for single-map localization

mapSetCode(code)

String

Sets the map set code for multi-map localization

enableMeshVisualization(enabled)

Boolean

Enables mesh visualization after localization

backgroundLocalization(enabled)

Boolean

Enables background localization

build()

-

Builds the configuration object


Public Methods

setupUI()

Initializes the UI components and sets up button click listeners:

  • Single Frame localization button

  • Multi Frame localization button

  • Authentication retry button

initializeSDK()

Initializes the MultiSet SDK with credentials from BuildConfig:

  • Validates that clientId and clientSecret are configured

  • Validates that either mapCode or mapSetCode is configured

  • Builds the SDK configuration

  • Calls MultiSetSDK.initialize()

checkCameraPermission()

Checks and requests camera permission using the Android Activity Result API.

Returns: Boolean - true if permission is already granted, false if permission request was launched.

checkARCoreAndProceed()

Checks ARCore availability and installation status:

  • If ARCore is installed, proceeds to start AR session

  • If ARCore needs installation, requests installation

  • If ARCore is not supported, shows error message

startARSession()

Launches the MultiSetLocalizationActivity with the selected localization mode passed as an intent extra:


Callbacks (MultiSetCallback Interface)

onSDKReady()

Called when the SDK has been initialized and is beginning authentication.

onAuthenticationSuccess()

Called when authentication with the MultiSet backend is successful.

onAuthenticationFailure(error: String)

Called when authentication fails.

Parameter
Type
Description

error

String

Error message describing the failure reason

onLocalizationSuccess(result: LocalizationResult)

Called when localization succeeds. The result can be logged or used by the host application.

Parameter
Type
Description

result

LocalizationResult

Contains map code, map codes list, position, rotation, confidence, and optional geo-coordinates

onLocalizationFailure(error: String)

Called when localization fails. In MainActivity, this is handled by the AR activity.

Parameter
Type
Description

error

String

Error message describing the failure reason

onTrackingStateChanged(state: TrackingState)

Called when AR tracking state changes. In MainActivity, this is handled by the AR activity.

Parameter
Type
Description

state

TrackingState

Current tracking state (TRACKING, PAUSED, STOPPED)


LocalizationResult

Property
Type
Description

mapCode

String

The code of the map where localization succeeded

mapCodes

List<String>

All map codes returned by the localization API

position

FloatArray

XYZ position coordinates

rotation

FloatArray

XYZW quaternion rotation

confidence

Float?

Confidence score of the localization (0.0 - 1.0)

geoCoordinates

GeoCoordinates?

Optional geographic coordinates


TrackingState

Value
Description

TRACKING

AR tracking is working normally

PAUSED

AR tracking is temporarily paused

STOPPED

AR tracking has stopped


Usage Example


Last updated