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

Glasses Keys and System Broadcasts

Android: Glasses Keys and System Broadcasts

Overview

Rokid glasses leg keys and touchpad events arrive as system broadcasts. CXRSWithCXRLSample dynamically registers a BroadcastReceiver in MainActivity, converts events to strings, and reports them via CXRServiceBridge.sendMessage(“rk_custom_key”, Caps) — same reply channel as Custom Commands.

Activity onKeyDown / onKeyUp and OnBackPressedCallback also call sendMessage to compare broadcast vs KeyEvent paths.

Prerequisites

  • CXRServiceBridge initialized and subscribe registered (see Custom Commands chapter).
  • CustomApp session built; phone Custom Commands page can receive rk_custom_key.

KeyType system broadcasts

KeyReceiver enum and actions:

KeyTypeAction
CLICKcom.android.action.ACTION_SPRITE_BUTTON_CLICK
BUTTON_DOWNcom.android.action.ACTION_SPRITE_BUTTON_DOWN
BUTTON_UPcom.android.action.ACTION_SPRITE_BUTTON_UP
DOUBLE_CLICKcom.android.action.ACTION_SPRITE_BUTTON_DOUBLE_CLICK
LONG_PRESScom.android.action.ACTION_SPRITE_BUTTON_LONG_PRESS
AI_STARTcom.android.action.ACTION_AI_START
ACTION_TWO_FINGER_SINGLE_TAPcom.android.action.ACTION_TWO_FINGER_SINGLE_TAP
ACTION_TWO_FINGER_DOUBLE_TAPcom.android.action.ACTION_TWO_FINGER_DOUBLE_TAP
ACTION_TWO_FINGER_SWIPE_FORWARDcom.android.action.ACTION_TWO_FINGER_SWIPE_FORWARD
ACTION_TWO_FINGER_SWIPE_BACKcom.android.action.ACTION_TWO_FINGER_SWIPE_BACK
ACTION_SETTINGS_KEYcom.android.action.ACTION_SETTINGS_KEY

Dynamic registration

Sample registers in MainActivity.onCreate, unregisters in onDestroy:

registerReceiver(viewModel.keyReceiver, IntentFilter().apply {
KeyType.entries.forEach { addAction(it.action) }
})
override fun onDestroy() {
unregisterReceiver(viewModel.keyReceiver)
super.onDestroy()
}

KeyReceiver.onReceive dispatches to KeyEventListener.onKeyEvent and calls abortBroadcast() to avoid duplicate handling.

Relation to sendMessage

override fun onKeyEvent(keyType: KeyType) {
sendMessage(“Listener: key action = ${keyType.name})
}
viewModel.sendMessage(“Down keyCode = $keyCode, event = ${event?.action})
viewModel.sendMessage(“Back Pressed”)

Phone parses in CustomCmdViewModel.onCustomCmdResult(“rk_custom_key”, …).

Permissions

  • Sample does not declare these actions in Manifest; relies on system ordered broadcasts to registered receivers.
  • Runtime registration only; no extra CXR permissions for keys themselves.
  • Using abortBroadcast may affect other receivers — validate on target devices.

Constraints

  • Actions may expand with OS versions; validate on hardware.
  • High-frequency keys: mind Caps size and phone UI refresh.
  • Always unregisterReceiver in onDestroy.

Appendix: Sample

FileRole
receiver/KeyReceiver.ktKeyType actions, abortBroadcast
activities/main/MainActivity.ktDynamic register, KeyEvent, back
activities/main/MainViewModel.ktkeyReceiver, sendMessage
Marcin Miazga