MainActivity
Overview
The MainActivity serves as the entry point for the MultiSet SDK demo application. It demonstrates SDK initialization, authentication handling, and navigation to AR localization activities.
Description
This activity is responsible for:
Initializing the MultiSet SDK with credentials
Handling the authentication flow
Managing camera and ARCore permissions
Launching single-frame or multi-frame AR localization sessions
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
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
MultiSetSDK.initialize(context, config, callback)
Initializes the SDK with configuration and callback
MultiSetConfig.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 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
clientIdandclientSecretare configuredValidates that either
mapCodeormapSetCodeis configuredBuilds 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 appropriate AR activity based on the selected localization mode:
LocalizationMode.SINGLE_FRAME->SingleFrameARActivityLocalizationMode.MULTI_FRAME->MultiFrameARActivity
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.
error
String
Error message describing the failure reason
onLocalizationSuccess(result: LocalizationResult)
Called when localization succeeds. In MainActivity, this is handled by the AR activities.
result
LocalizationResult
Contains map ID, position, rotation, confidence, and optional geo-coordinates
onLocalizationFailure(error: String)
Called when localization fails. In MainActivity, this is handled by the AR activities.
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 activities.
state
TrackingState
Current tracking state (TRACKING, PAUSED, STOPPED)
LocalizationResult
mapId
String
The ID of the map where localization succeeded
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