CXR-L(EN)
cxr-l-sdk · v1.0.3 · snapshot 2026-06-02· ↗ source

Connection and Session

Android: Connection and Session

Overview

Create CXRLink, configure the session type (CUSTOMVIEW or CUSTOMAPP), register link callbacks, and call connect(token) to establish a collaborative session between the phone and glasses. Reuse a single CXRLink instance per process for Custom View/app control and subsequent audio, photo, and custom command capabilities.

Prerequisites

  • Authentication completed with a non-empty token.

Core types

TypePackage
CXRLinkcom.rokid.cxr.link.CXRLink
CxrDefs.CXRSessioncom.rokid.cxr.link.utils.CxrDefs
CxrDefs.CXRSessionTypeCUSTOMVIEW / CUSTOMAPP
ICXRLinkCbkcom.rokid.cxr.link.callbacks.ICXRLinkCbk

Session configuration

CustomView session

Delivers custom view JSON; no glasses-side target package.

val link = CXRLink(context).apply {
configCXRSession(CxrDefs.CXRSession(CxrDefs.CXRSessionType.CUSTOMVIEW))
setCXRLinkCbk(linkCallback)
setCXRCustomViewCbk(customViewCallback)
}
application.sharedLink = link
link.connect(token)

CustomApp session

Remote install/start/stop of a glasses-side Android app; requires target package name.

val targetPackage = “com.example.glasses.app”
val link = CXRLink(context).apply {
configCXRSession(
CxrDefs.CXRSession(
CxrDefs.CXRSessionType.CUSTOMAPP,
targetPackage
)
)
setCXRLinkCbk(linkCallback)
}
application.sharedLink = link
link.connect(token)

ICXRLinkCbk callbacks

CallbackMeaning
onCXRLConnected(Boolean)CXR service connection state
onGlassBtConnected(Boolean)Glasses Bluetooth connection state
onGlassAiAssistStart() / onGlassAiAssistStop()Wake-word activation
onGlassAiInterrupt(Boolean)AI interrupt event
onGlassDeviceInfo(GlassInfo)Device information
onGlassWearingStatus(Boolean)Wearing detection

Both CustomView and CustomApp require:

  • onCXRLConnected(true) — CXR service connected
  • onGlassBtConnected(true) — glasses Bluetooth ready

Do not call customViewSetIcons, customViewOpen, CustomApp install/start, or sub-capabilities until both are true. RenewCXRLSample sets isSessionReady and Hub _sessionReady using this conjunction.

Link ready ≠ scene building complete on the glasses.

connect return value

connect(token) returns Boolean indicating whether the connection request was initiated. Final state comes from ICXRLinkCbk callbacks.

Rendering diagram…

Lifecycle rules

  1. Register setCXRLinkCbk once per process (Application or connection hub singleton).
  2. Sub-pages (audio/photo/cmd) must not call disconnect() — only stop local SDK usage.
  3. On true session end (Activity.isFinishing), call customViewClose() or appStop().
  4. When navigating between hub and sub-pages, keep Custom View / glasses app open.

Constraints

  • Call configCXRSession before connect.
  • Recreate CXRLink when switching session types.
  • Avoid multiple parallel connect calls from different instances.

Next steps

  • CustomView → Glasses Custom View
  • CustomApp → Glasses Custom App

Appendix: reference sample

RenewCXRLSample: CxrSessionGate, CxrLinkConnectionHub, SessionHubViewModel.

Marcin Miazga