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

Custom Commands

Android: Custom Command

Scenario

On an established CUSTOMAPP session and the same CXRLink instance, use Caps to serialize the payload, send a custom command to the glasses via sendCustomCmd, and receive responses in ICustomCmdCbk. In CXRLSample, the send button is enabled only when entering from the CustomApp flow and entryType is customApp.

Prerequisites

  • In CustomCmdViewModel.init, _available = (entryType == ENTRY_TYPE_CUSTOM_APP).
  • CXRLSampleApplication.sharedCxrLink is not null (i.e., you have gone through CustomAppTypeViewModel.init and called connect).
  • The glasses-side Custom App scene has been built: the target app has been opened on the glasses via openApp, etc. (in the Sample, the entry to CustomCmdActivity is provided only after appOpened == true in CustomAppTypeScreen; do not send commands immediately after connect succeeds while the app is not launched yet).

Under CUSTOMVIEW, the Sample sets _available to false and does not demonstrate sending (aligned with product constraints: custom commands should be used within a glasses-side app session).

Key APIs

MethodDescription
setCXRCustomCmdCbk(ICustomCmdCbk)Register callback.
sendCustomCmd(key: String, payload: ByteArray)Send. The Sample uses Caps().serialize() as payload.

Callback

onCustomCmdResult(key: String?, payload: ByteArray?):

  • The Sample handles responses only when key == “rk_custom_key”.
  • It deserializes via Caps.fromBytes(payload) and recursively renders with parseCaps into the UI.

Send example (same as the Sample)

cxrLink.sendCustomCmd(“rk_custom_client”, Caps().apply {
write(“rk_custom_key”)
write(“from client click times = ${count++})
}.serialize())

The glasses side must agree on channels/keys such as rk_custom_client / rk_custom_key and their semantics.

Constraints

  • Send only when onCXRLConnected(true) and Bluetooth is in an available state. The Sample gates this via _ready.
  • Protocol version, endianness, and maximum packet size must match the glasses side, otherwise you may see silent failure or truncation.
  • On page release, set _ready to false to avoid background sends.

Sample reference paths

  • activities/customCMD/CustomCmdViewModel.kt
  • activities/customCMD/CustomCmdActivity.kt
Marcin Miazga