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:
Initializing the MultiSet SDK with credentials
Handling the authentication flow
Managing camera and ARCore permissions
Launching the unified
MultiSetLocalizationActivityfor single-frame or multi-frame localizationLaunching
ObjectTrackingActivityfor 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
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
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
MultiSetSDKConfig.Builder
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
SettingsDialogFragmentto editLocalizationConfig/ObjectTrackingConfigat runtime)
Persisted configuration is restored before any AR activity reads it:
MainActivity.onCreate()callsConfigStore.load(this), which applies the values saved from the Settings dialog. Credentials and map / object codes are always sourced frommultiset.propertiesand 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.
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.
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.
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.
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.
state
TrackingState
Current tracking state (TRACKING, PAUSED, STOPPED)
onObjectTrackingSuccess(result: ObjectTrackingResult)
Called when an object is successfully tracked. Forwarded from ObjectTrackingActivity via MultiSetSDK.getCallback().
result
ObjectTrackingResult
Contains object code, pose data, and confidence
onObjectTrackingFailure(error: String)
Called when object tracking fails.
error
String
Error message describing the failure reason
LocalizationResult
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
TRACKING
AR tracking is working normally
PAUSED
AR tracking is temporarily paused
STOPPED
AR tracking has stopped
Usage Example
Related
Last updated
Was this helpful?

