CXR-L(EN)
CXR-L(EN)
IntroductionQuick StartDevelopment Flow & State-MachineTerms and Abbreviations
Feature Development
Version HistoryAndroid
iOS
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
CXRServiceBridgeinitialized andsubscriberegistered (see Custom Commands chapter).- CustomApp session built; phone Custom Commands page can receive
rk_custom_key.
KeyType system broadcasts
KeyReceiver enum and actions:
| KeyType | Action |
|---|---|
CLICK | com.android.action.ACTION_SPRITE_BUTTON_CLICK |
BUTTON_DOWN | com.android.action.ACTION_SPRITE_BUTTON_DOWN |
BUTTON_UP | com.android.action.ACTION_SPRITE_BUTTON_UP |
DOUBLE_CLICK | com.android.action.ACTION_SPRITE_BUTTON_DOUBLE_CLICK |
LONG_PRESS | com.android.action.ACTION_SPRITE_BUTTON_LONG_PRESS |
AI_START | com.android.action.ACTION_AI_START |
ACTION_TWO_FINGER_SINGLE_TAP | com.android.action.ACTION_TWO_FINGER_SINGLE_TAP |
ACTION_TWO_FINGER_DOUBLE_TAP | com.android.action.ACTION_TWO_FINGER_DOUBLE_TAP |
ACTION_TWO_FINGER_SWIPE_FORWARD | com.android.action.ACTION_TWO_FINGER_SWIPE_FORWARD |
ACTION_TWO_FINGER_SWIPE_BACK | com.android.action.ACTION_TWO_FINGER_SWIPE_BACK |
ACTION_SETTINGS_KEY | com.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
abortBroadcastmay 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
unregisterReceiverinonDestroy.
Appendix: Sample
| File | Role |
|---|---|
receiver/KeyReceiver.kt | KeyType actions, abortBroadcast |
activities/main/MainActivity.kt | Dynamic register, KeyEvent, back |
activities/main/MainViewModel.kt | keyReceiver, sendMessage |