Authentication
Android: Authentication
Overview
Before calling CXRLink.connect(token), complete OAuth-style authorization through Rokid AI App (mainland China) or Hi Rokid (overseas) to obtain a communication token. The required app hosts the authorization UI; your app detects installation, starts the flow, and parses the result.
Prerequisites
- SDK Integration completed.
- Rokid AI App (≥ 1.7.14) or Hi Rokid installed (region-dependent).
Core APIs
| Step | API | Description |
|---|---|---|
| Check required app | AuthorizationHelper.isRequiredRokidAppInstalled(Activity) | Rokid AI App installed (mainland) |
| Check required app | AuthorizationHelper.isRequiredHiRokidInstalled(Activity) | Hi Rokid installed (overseas) |
| Region | AuthorizationHelper.isConnectHiRokid() | Whether Hi Rokid service is used |
| Start auth | AuthorizationHelper.requestAuthorization(Activity, permissions, requestCode) | Opens auth UI; pass required GlassPermission array |
| Parse result | AuthorizationHelper.parseAuthorizationResult(resultCode, Intent?) | Returns AuthResult |
GlassPermission
Request glasses-side runtime permissions during authorization, e.g.:
GlassPermission.MICROPHONE— audio captureGlassPermission.CAMERA— photo capture
Check grants with AuthorizationHelper.hasGlassPermission(GlassPermission.MICROPHONE) (and other GlassPermission values).
AuthResult branches
| Type | Handling |
|---|---|
AuthResult.AuthSuccess | Read token; non-empty means success |
AuthResult.AuthFail | Clear token |
AuthResult.AuthCancel | User cancelled; clear token |
Integration steps
1. Detect required app
when {
AuthorizationHelper.isRequiredRokidAppInstalled(activity) -> { /* Rokid AI ready */ }
AuthorizationHelper.isRequiredHiRokidInstalled(activity) -> { /* Hi Rokid ready */ }
else -> { /* Prompt install */ }
}
2. Start authorization
private const val AUTH_REQUEST_CODE = 1001
AuthorizationHelper.requestAuthorization(
activity,
arrayOf(GlassPermission.MICROPHONE),
AUTH_REQUEST_CODE
)
If the user was previously authorized, requestAuthorization may return (resultCode, data) immediately — parse it without waiting for onActivityResult.
3. Handle Activity callback
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == AUTH_REQUEST_CODE) {
when (val result = AuthorizationHelper.parseAuthorizationResult(resultCode, data)) {
is AuthResult.AuthSuccess -> {
val token = result.token
// Persist and proceed to session setup
}
is AuthResult.AuthFail, is AuthResult.AuthCancel -> {
// Prompt re-authorization
}
}
}
}
Important: The first argument to parseAuthorizationResult is resultCode, not requestCode.
Constraints
- Do not assume
connectsucceeds without a validtoken. - Authorization depends on the required app; your app cannot forge tokens.
- With client-l:1.0.3, Rokid AI App must be ≥ 1.7.14;
AuthorizationHelper.isRequiredRokidAppInstalledvalidates installation and minimum version. - Pass the token securely to the session Activity before connecting.
Next steps
Connection and Session — create CXRLink and call connect(token).
Appendix: reference sample
RenewCXRLSample MainViewModel and MainActivity demonstrate the full flow.