CXR-L(EN)
cxr-l-sdk · v1.0.1 · snapshot 2026-05-13· ↗ source

Connection and Session

Android: Connection and Session

Scenario

Create a CXRLink, configure the session type (CUSTOMVIEW or CUSTOMAPP), register link callbacks, and call connect(token) to establish a coordinated session between the phone and the glasses-side service. The Sample initializes this in CustomViewTypeViewModel / CustomAppTypeViewModel, and stores the instance in CXRLSampleApplication.sharedCxrLink for reuse by the audio/photo/custom-command pages.

Prerequisites

  • You have completed “02-Authentication” and obtained a non-empty token.

Key types

  • com.rokid.cxr.link.CXRLink
  • com.rokid.cxr.link.utils.CxrDefs.CXRSession / CxrDefs.CXRSessionType
  • com.rokid.cxr.link.callbacks.ICXRLinkCbk

Session configuration

CustomView

cxrLink = CXRLink(context).apply {
configCXRSession(CxrDefs.CXRSession(CxrDefs.CXRSessionType.CUSTOMVIEW))
setCXRLinkCbk(connectCallback)
setCXRCustomViewCbk(customViewCallback)
}
(application as? CXRLSampleApplication)?.sharedCxrLink = cxrLink
cxrLink.connect(token)

CustomApp (CUSTOMAPP)

cxrLink = CXRLink(context).apply {
configCXRSession(
CxrDefs.CXRSession(
CxrDefs.CXRSessionType.CUSTOMAPP,
CONSTANT.APP_PACKAGE_NAME // glasses-side target package, e.g. com.rokid.cxrswithcxrl
)
)
setCXRLinkCbk(connectCallback)
}
(application as? CXRLSampleApplication)?.sharedCxrLink = cxrLink
cxrLink.connect(token)

For CUSTOMAPP, you also need to prepare an APK path for installation in your business flow (see “Glasses-side Custom App”).

CallbackMeaning (Sample usage)
onCXRLConnected(Boolean)CXR service connection state. In CustomView, when true and icon JSON is ready, the Sample calls customViewSetIcons.
onGlassBtConnected(Boolean)Glasses Bluetooth connection. When false, mark audio/photo as not ready.
onGlassAiAssistStart/Stop()Wake word activation.

CustomAppTypeViewModel defines “connected successfully” as both CXR and Bluetooth being true.

connect return value

connect returns a Boolean indicating whether the connection request is successfully initiated. Final connectivity must be determined by callbacks.

Constraints

  • configCXRSession must be called before connect.
  • Within the same process, reuse a single CXRLink instance to avoid duplicated connect and inconsistent state (the Sample uses an Application field).
  • Switching session type typically requires creating a new CXRLink and re-configuring it (the Sample routes via different Activities).
  • Transport ready ≠ scene ready: onCXRLConnected and onGlassBtConnected only indicate transport readiness. Photo capture, audio, and custom commands still require the glasses-side Custom View opened or Custom App opened.

Sample reference paths

  • activities/customViewType/CustomViewTypeViewModel.kt
  • activities/customAppType/CustomAppTypeViewModel.kt
  • CXRLSampleApplication.kt
Marcin Miazga