For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

  5. Launching ObjectTrackingActivity for AR object detection and tracking

The landing page uses a card-based layout:

  • Settings Gear: top-right icon that opens the Settings dialog to edit localization & object-tracking configuration at runtime

  • Auth Button: full-width, shows authentication state

  • Localization Card: displays map code, a mode toggle (Single Frame / Multi Frame), and a Start Localization button

  • Object Tracking Card: displays configured object codes and a Start Object Tracking button


Authentication Flow

1. SDK Initialization

The SDK is initialized using credentials from BuildConfig:

In the sample app this is wrapped by MultiSetSDKInit.initialize(context, callback), which reads the BuildConfig fields produced from multiset.properties, applies the optional MULTISET_BASE_URL override, and returns false (rather than throwing) when credentials or every map and object code are missing, so the UI can show a setup message.

2. Configuration Builder Options

Method
Description

mapCode(String)

Set a single map code for localization

mapSetCode(String)

Set a mapSet code for localizing against multiple maps

objectCodes(List<String>)

Set the object codes to track (maximum 10)

localizationMode(LocalizationMode)

SINGLE_FRAME or MULTI_FRAME

enableMeshVisualization(Boolean)

Enable/disable 3D mesh overlay visualization

backgroundLocalization(Boolean)

Enable/disable background localization

poseConsistencyCheck(Boolean)

Enable/disable false-positive rejection

poseConsistencyThreshold(Float)

Tolerance in metres, 3 to 30

baseUrl(String)

Point the SDK at a staging or on-premise API host

The builder exposes the full configuration surface, including confidence settings, localization hints, GPS options, frame counts and image quality. See LocalizationConfig for the meaning of each value.

3. Authentication Callbacks

The activity implements MultiSetSDKCallback to receive authentication events:


APIs Used for Authentication

MultiSetSDK

Method
Description

MultiSetSDK.initialize(context, config, callback)

Initializes the SDK with configuration and callback

MultiSetSDK.isAuthenticated()

Whether a valid token is currently held

MultiSetSDK.getVersion()

The SDK version string

MultiSetSDK.localizationSession(frameSource, mode)

Creates a localization session

MultiSetSDK.objectTrackingSession(frameSource, objectCodes)

Creates an object tracking session

MultiSetSDK.resetPoseConsistencyReference()

Re-bootstraps the false-positive reference anchor

MultiSetSDK.release()

Releases SDK resources

MultiSetSDK.getLastLocalizationResult() was removed in 1.16.0. Results are delivered through the session callbacks instead. See FrameSource and Sessions.

MultiSetSDKConfig.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 mapSet code for multi-map localization

enableMeshVisualization(enabled)

Boolean

Enables mesh visualization after localization

backgroundLocalization(enabled)

Boolean

Enables background localization

build()

-

Builds the configuration object


Structure

MainActivity is the landing screen. It initializes the SDK, reflects authentication state in the UI, and launches the two AR activities.

setupUI()

Initializes the UI components and sets up button click listeners:

  • Mode toggle group (Single Frame / Multi Frame selection)

  • Start Localization button

  • Start Object Tracking button

  • Settings gear (opens SettingsDialogFragment to edit LocalizationConfig / ObjectTrackingConfig at runtime)

Persisted configuration is restored before any AR activity reads it: MainActivity.onCreate() calls ConfigStore.load(this), which applies the values saved from the Settings dialog. Credentials and map / object codes are always sourced from multiset.properties and are never persisted.

displayMapCode() and displayObjectCodes()

Render the configured map (or mapSet) code and the object code list on the landing cards, so it is obvious which environment and objects the build is pointed at.

showConfigurationAlert()

Shown when MultiSetSDKInit.initialize() returns false, meaning credentials or all map and object codes are missing from multiset.properties.

Launching the AR activities

Camera permission and ARCore availability are requirements of the AR activities, which use ARCore through Sceneform. They are not requirements of the SDK itself.


Callbacks (MultiSetSDKCallback Interface)

onSDKReady()

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

onAuthenticationSuccess()

Called when authentication with the MultiSet backend is successful. Enables the Localization and Object Tracking buttons and updates the auth button to show a green "Authenticated" state.

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

onLocalizationFalsePositive(info: FalsePositiveInfo)

Called when a localization response was discarded because it contradicted the device's own AR trajectory. The request succeeded; the answer was wrong. The scene is left untouched.

Parameter
Type
Description

info

FalsePositiveInfo

Jump distance, threshold, consecutive count, map codes, confidence and reason

This callback has a default no-op implementation, so it is optional to override.

onTrackingStateChanged(state: TrackingState)

Called when AR tracking state changes. Handled internally by the AR activities.

Parameter
Type
Description

state

TrackingState

Current tracking state (TRACKING, PAUSED, STOPPED)

onObjectTrackingSuccess(result: ObjectTrackingResult)

Called when an object is successfully tracked. Forwarded from ObjectTrackingActivity via MultiSetSDK.getCallback().

Parameter
Type
Description

result

ObjectTrackingResult

Contains object code, pose data, and confidence

onObjectTrackingFailure(error: String)

Called when object tracking fails.

Parameter
Type
Description

error

String

Error message describing the failure reason


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

Was this helpful?