successful result or an error.
Before using any Spectacles Mobile Kit features, your app must explicitly request BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions from the user.
The main entry point for working with the Spectacles Mobile Kit. It manages bonding and session setup between your app and Spectacles.
interface SpectaclesKitfun bind(
request: BondingRequest,
onResult: Consumer<BondingResult>
): ClosableInitiates a secure bonding process with the Lens specified in the provided BondingRequest.
| Parameters | |
|---|---|
| request | Identifies the Lens to bind with. |
| onResult | Callback to receive the bonding result. |
| Returns | |
|---|---|
| Closable | Represents the ongoing bonding process. Call close() to cancel it if needed. |
fun unbind(
id: String,
onResult: Consumer<UnbindingResult>,
graceful: Boolean = true
): ClosableEnds an existing secure bonding with a Lens.
| Parameters | |
|---|---|
| id | The ID of the bonding to revoke. |
| onResult | Callback to receive the unbinding result. |
| graceful | Whether to unbind gracefully. Default is true |
| Returns | |
|---|---|
| Closable | Represents the ongoing unbinding process. Call close() to cancel it if needed. |
fun avaliableBondings(): List<Bonding>Returns all available bondings.
| Returns | |
|---|---|
| List<Bonding> | A list of existing bondings. |
fun getBonding(id: String): Bonding?Fetches the Bonding associated with the given id.
| Parameters | |
|---|---|
| id | The bonding ID. |
| Returns | |
|---|---|
| Bonding | The bonding if found, or null if not available. |
fun createSession(
bonding: Bonding,
request: SessionRequest,
delegateBuiler: (SpectaclesSession) -> SpectaclesRequestDelegate
): SpectaclesSessionCreates a session to communicate with the bounded Lens.
| Parameters | |
|---|---|
| bonding | The secure bonding to use. |
| request | The session settings. |
| delegateBuilder | Factory for creating a delegate to handle session requests. |
| Returns | |
|---|---|
| SpectaclesSession | The created session |
Used to create a SpectaclesKit instance with required app credentials.
interface Builderfun setIdentifier(identifier: ClientIdentifier): BuilderSet the unique identifier for your application.
| Parameters | |
|---|---|
| identifier | The app’s client identifier |
| Returns | |
|---|---|
| Builder | For chaining |
fun setVersion(version: String): BuilderSet the app version.
| Parameters | |
|---|---|
| version | The app version |
| Returns | |
|---|---|
| Builder | For chaining |
fun setRequestExecutor(executor: Executor): BuilderSets the executor used to handle Lens requests.
| Parameters | |
|---|---|
| executor | The requests executor. |
| Returns | |
|---|---|
| Builder | For chaining |
fun build(): SpectaclesKitBuilds and returns a SpectaclesKit instance.
| Returns | |
|---|---|
| SpectaclesKit | The SpectaclesKit instance. |
Creates a SpectaclesKit.Builder with the provided context.
fun newBuilder(contex: Context): SpectaclesKit.Bulder| Parameters | |
|---|---|
| context | Android context |
Represents your app's unique identifier.
data class ClientIdentifier(val value: String)val value: StringThe client identifier.
Represents a request to initiate bonding with a specific Lens.
sealed class BondingRequest {
data class SingleLensByLensId(val lensId: String) : BondingRequest()
data class SingleLensByLensName(val lensName: String) : BondingRequest()
}Request to bind with a Lens using its unique ID.
data class SingleLensByLensId(val lensId: String) : BondingRequestval lensId: StringThe unique identifier of the Lens to bind with.
Request to bind using a Lens's name.
data class SingleLensByLensName(val lensName: String) : BondingRequestval lensName: StringThe name of the Lens to bind with.
Represents the result of a bonding attempt.
sealed class BondingResult {
data class Success(val bonding: Bonding) : BondingResult()
data class Failure(val exception: Exception) : BondingResult()
}Indicates a successful bonding.
data class Success(val bonding: Bonding) : BondingResultval bonding: BondingThe resulting Bonding instance.
Indicates a bonding failure.
data class Failure(val exception: Exception) : BondingResultval exception: ExceptionThe exception that caused the failure.
Represents a secure bonding between the app and a Lens.
interface Bonding(val id: String)val id: StringThe unique ID of the bonding.
Represents the result of an unbinding operation.
sealed class UnbindingResult {
data object Success : UnbindingResult()
data class Failure(val exception: Exception) : UnbindingResult()
}Indicates a successful unbinding.
data object Success : UnbindingResultIndicates an unbinding failure.
data class Failure(val exception: Exception) : UnbindingResultval exception: ExceptionThe exception that caused the failure.
Base class for exceptions related to SpectaclesKit client errors.
open class ClientException(
message: String,
cause: Exception? = null
) : Exception(message, cause) {
/**
* Exception thrown when the Lens SpectaclesKit is not installed.
*/
class LensClientNotInstalled(message: String) : ClientException(message)
/**
* Exception thrown when the specified device is not found.
*/
class DeviceNotFound(message: String): ClientException(message)
/**
* Exception thrown when the Spectacles app is not installed.
*/
class SpectaclesAppNotInstalled(message: String): ClientException(message)
/**
* Exception thrown when the Spectacles app is not enabled.
*/
class SpectaclesAppNotEnabled(message: String): ClientException(message)
/**
* Exception thrown when the Spectacles app needs to be updated.
*/
class SpectaclesAppUpdateRequired(message: String): ClientException(message)
}Represents configuration options for establishing a session with Spectacles.
sealed abstract class SessionsRequestval autoReconnect: BooleanIf true, the session will try to reconnect automatically.
val acceptUnfusedSpectacles: BooleanAllows connections to unfused (debug) Spectacles.
val preSharedSecret: Pair<ByteArray, ByteArray>?Internal use only.
val acceptUntrustedLens: BooleanAllows untrusted Lens connections, useful for development with Lenses pushed from Lens Studio.
A default implementation of SessionRequest with standard values.
data class Default(
override val autoReconnect: Boolean = true,
override val acceptUnfusedSpectacles: Boolean = false,
override val preShareSecret: Pair<ByteArray, ByteArray>? = null,
override val acceptUntrustedLens: Boolean = false
) : SessionRequestRepresents an active session for connecting to and interacting with a specific Lens.
interface SpectaclesSessionfun observeConnectionStatus(onStatus: Consumer<ConnectionStatus>): ClosableSubscribes to connection status updates for the session.
| Parameters | |
|---|---|
| onStatus | Callback that receives updates when the connection status changes. |
| Returns | |
|---|---|
| Closable | Call close() to unsubscribe from status updates. |
fun connectionStatus(): ConnectionStatusRetrieves the current connection status of the session.
| Returns | |
|---|---|
| ConnectionStatus | The current session state. |
fun close(reason: ClonseReason?)Closes the session and terminates the connection.
| Parameters | |
|---|---|
| reason | (Optional) Reason for closing the session. |
Defines possible reasons for manually closing a session.
enum class CloseReason| Values | |
|---|---|
| INCOMPATIBLE_LENS | The connected Lens is incompatible. |
Defines reasons for unexpected disconnection.
enum class DisconnectReason| Values | |
|---|---|
| SESSION_CLOSED | The session was explicitly closed by the caller. |
| CONNECTION_LOST | Connection was lost, likely due to network issues. |
Represents the current state of the connection to a Lens.
sealed class ConnectionStatus {
object ConnectStart : ConnectionStatus()
data class Connected(val sessionMetadata: Metadata) : ConnectionStatus
data class Error(val exception: Exception) : ConnectionStatus
data class Disconnected(val reason: DisconnectReason) : ConnectionStatus
}Indicates the session is starting a connection.
object ConnectStart : ConnectionStatusConnection successfully established.
data class Connected(val sessionMetadata: Metadata) : ConnectionStatusval sessionMetadata: MetadataThe Metadata about the connected Lens.
The connection attempt failed.
data class Error(val exception: Exception) : ConnectionStatusval exception: ExceptionProvides the error details.
The session was disconnected.
data class Disconnected(val reason: DisconnectReason) : ConnectionStatusval reason: DisconnectReasonExplains the cause of disconnection.
Provides information about the connected Lens.
data class Metadata(
val lensId: String,
val lensVersion: String
)val lensId: StringThe unique identifier of the Lens.
val lensVersion: StringThe version of the connected Lens.
Implement this interface to handle incoming requests from a connected Lens.
interface SpectaclesRequestDelegatefun processServiceRequest(request: SpectaclesReqeust)Invoked when the connected Lens sends a request.
| Parameters | |
|---|---|
| request | The incoming SpectaclesRequest from the Lens that needs to be processed. |
Base class for different types of Lens requests.
sealed interface SpectaclesRequestDescribes a request that does not expect a response (e.g., an event).
abstract class WithoutResponse : SpectaclesRequestRepresents a request that expects a single response (e.g., a one-time request).
abstract class WithResponse<Payload: Any> : SpectaclesRequestabstract val onResponse: Consumer<Payload>Invoked to deliver a successful response.
abstract val onError: Consumer<SpectaclesRequestException>Invoked to report an error.
Represents a request that may produce multiple responses (e.g., a subscription).
abstract class WithResponses<Payload: Any> : SpectaclesRequestabstract val onResponse: Consumer<Payload>Invoked to deliver a successful response.
abstract val onError: Consumer<SpectaclesRequestException>Invoked to report an error.
Base class for all response types.
sealed class Response<Payload: Any>abstract val payload: PayloadThe concrete response payload.
Represents an intermediate response, indicating that more responses will follow.
Typically used for subscription-style requests.
data class Ongoing<Payload: Any>(
override val payload: Payload
) : Response<Payload>Represents the final response.
Once a Complete is delivered, no further responses will be sent for the request.
data class Complete<Payload: Any>(
override val payload: Payload
) : Response<Payload>Base interface for all Lens API requests.
sealed interface SpectaclesApiRequestEncapsulates the method name and raw parameters for an API request.
data class Payload(
val method: String,
val params: ByteArray
)val method: StringThe name of the API method being invoked.
val params: ByteArrayThe serialized parameters for the API method.
Represents an API call that expects one or more responses (e.g., a request or subscription).
data class Call(
val payload: Payload,
override val onResponse: Consumer<Payload>
override val onError: Consumer<SpectaclesRequestException>
) : SpectaclesApiRequest, SpectaclesRequest.WithResponses<ByteArray>()val payload: PayloadThe payload (method and parameters) of this API call.
val onResponse: Consumer<Payload>Called to deliver one or more successful responses.
val onError: Consumer<SpectaclesRequestException>Called to report an error.
Represents a one-way API notification (event) that does not expect a response.
data class Notify(
val payload: Payload
) : SpectaclesApiRequest, SpectaclesRequest.WithoutResponses()val payload: PayloadThe payload (method and parameters) of this API notification.
Base interface for all Lens asset requests.
sealed interface SpectaclesAssetRequestRepresents a request from the Lens to load a SpectaclesAsset from the app.
data class Load(
val path: String,
val version: String?,
override val onResponse: Consumer<SpectaclesAsset>,
override val onError: Consumer<SpectaclesRequestException>,
) : SpectaclesAssetRequest, SpectaclesRequest.WithResponse<SpectaclesAsset>()val path: StringThe path or URI of the requested SpectaclesAsset.
val version: String?The version of the asset currently cached on Spectacles (if any).
This may be a file checksum or timestamp, as determined by the SDK or
Lens developer.
The app can use this to decide whether to:
-
return a new version of the asset, or
-
indicate that the cached version is still up-to-date.
val onResponse: Consumer<SpectaclesAsset>Called to deliver the asset response to the Lens.
Should be invoked exactly once.
val onError: Consumer<SpectaclesRequestException>Called to report an error if the asset cannot be provided.
Base class for responses payload to a SpectaclesAssetRequest.
sealed class SpectaclesAssetRepresents the content of an asset to be delivered to the Lens.
data class Content(
val version: String?,
val assetSize: Long,
val dataStream: InputStream
) : SpectaclesAsset()val version: String?The version identifier of the asset being delivered.
This will be returned back to the app in future requests for version comparison.
val assetSize: LongThe total size of the asset in bytes.
val dataStream: InputStreamThe binary content of the asset, streamed to the Lens.
Indicates that the cached version of the asset on Spectacles is current and does not need to be updated.
data object UpToDate : SpectaclesAsset()Exception thrown when a request to the Spectacles fails.
open class SpectaclesRequestException(
statusCode: Int
) : SpectaclesStreamException(statusCode) {
/**
* Default state or unset.
*/
data object Unknown : SpectaclesRequestException(500)
/**
* Redirected. Corresponds to the 3XX HTTP response status codes.
*/
data object Redirected : SpectaclesRequestException(302)
/**
* Bad request. Corresponds to the 4XX HTTP response status codes other
* than 401, 403, 404, 408, 413, 414, and 431.
*/
data object BadRequest : SpectaclesRequestException(400)
/**
* Access denied. Corresponds to the HTTP response status codes 401 and 403.
*/
data object AccessDenied : SpectaclesRequestException(403)
/**
* Not found. Corresponds to the HTTP response status code 404.
*/
data object NotFound : SpectaclesRequestException(404)
/**
* Timeout. Corresponds to the HTTP response status codes 408 and 504.
*/
data object Timeout : SpectaclesRequestException(504)
/**
* Request too large. Corresponds to the HTTP response status codes 413, 414, and 431.
*/
data object RequestTooLarge : SpectaclesRequestException(413)
/**
* Server error. Corresponds to the 5XX HTTP response status codes other than 504.
*/
data object ServerError : SpectaclesRequestException(500)
/**
* Request cancelled by the caller.
*/
data object RequestCancelled : SpectaclesRequestException(409)
/**
* Internal error in the remote API framework.
*/
data object InternalError : SpectaclesRequestException(500)
}Interface for logging functionality.
Allows setting a custom logging provider that can be used across the application.
interface Log@JvmStatic val provider: ((String) -> Log?)? = nullHolds the current logging provider instance used to create Log instances.
If set to null, logging will be disabled.
@JvmStatic fun get(String): LogRetrieves a Log instance associated with the given tag.
fun enabled(): BooleanReturns true if logging is enabled.
fun verbose(message: () -> String)Sends a VERBOSE log message.
fun info(message: () -> String)Sends an INFO log message.
fun debug(message: () -> String)Sends a DEBUG log message.
fun warn(message: () -> String)Sends a WRAN message without a stack trace.
fun warn(throwable: Throwable, message: () -> String)Sends a WRAN message with a stack trace.
fun err(message: () -> String)Sends an ERROR message without a stack trace.
fun err(throwable: Throwable, message: () -> String)Sends an ERROR message with a stack trace.
This implements the Log interface using the Android logging class.
class System(private val tag: String) : LogA built-in Log implementation that disables all logging.
All log methods are no-ops, and enabled() always returns false.
class Disabled(private val tag: String) : Log