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
| Type | Package |
|---|---|
CXRLink | com.rokid.cxr.link.CXRLink |
CxrDefs.CXRSession | com.rokid.cxr.link.utils.CxrDefs |
CxrDefs.CXRSessionType | CUSTOMVIEW / CUSTOMAPP |
ICXRLinkCbk | com.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
| Callback | Meaning |
|---|---|
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 |
Link-ready criteria
Both CustomView and CustomApp require:
onCXRLConnected(true)— CXR service connectedonGlassBtConnected(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.
Recommended architecture
Lifecycle rules
- Register
setCXRLinkCbkonce per process (Application or connection hub singleton). - Sub-pages (audio/photo/cmd) must not call
disconnect()— only stop local SDK usage. - On true session end (
Activity.isFinishing), callcustomViewClose()orappStop(). - When navigating between hub and sub-pages, keep Custom View / glasses app open.
Constraints
- Call
configCXRSessionbeforeconnect. - Recreate
CXRLinkwhen switching session types. - Avoid multiple parallel
connectcalls from different instances.
Next steps
- CustomView → Glasses Custom View
- CustomApp → Glasses Custom App
Appendix: reference sample
RenewCXRLSample: CxrSessionGate, CxrLinkConnectionHub, SessionHubViewModel.