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

Authentication

Android: Authentication

Scenario

Before calling CXRLink.connect(token), you must complete an OAuth-like authorization via Rokid AI App to obtain the communication token. CXRLSample uses AuthorizationHelper provided by Rokid AI App to start and parse the authorization.

Prerequisites

  • Rokid AI App is installed on the phone (refer to MainViewModel.checkRokidAIAppInstalled).
  • You have completed “SDK Import”.

Key APIs (Sample)

StepAPI / typeDescription
Check installationAuthorizationHelper.INSTANCE.isRequiredRokidAppInstalled(Activity)Determines whether the home page shows branches such as “go install”.
Start authorizationAuthorizationHelper.INSTANCE.requestAuthorization(Activity, requestCode)Opens the authorization UI; requestCode should match onActivityResult.
Parse resultAuthorizationHelper.INSTANCE.parseAuthorizationResult(requestCode, Intent?)Returns an AuthResult subtype.

Typical AuthResult branches (see MainViewModel.checkAuthorizationResult):

  • AuthResult.AuthSuccess: read token and mark as authorized.
  • AuthResult.AuthFail: failure; clear token.
  • Others (e.g., cancel): treated as unauthorized per Sample logic.

Activity callback

Override onActivityResult in the host Activity (the Sample uses MainActivity):

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CONSTANT.AUTH_REQUEST_CODE) {
viewModel.checkAuthorizationResult(resultCode, data)
}
}

Note: the Sample passes resultCode as the first parameter of parseAuthorizationResult and aligns with the comment “matches what the current SDK parser expects”. When integrating, do not arbitrarily swap it to requestCode unless you have verified the SDK version’s expectation.

Constraints

  • When unauthorized, do not assume connect will succeed.
  • Authorization UI is hosted by Rokid AI App; your app only performs redirection and result parsing.

Sample reference paths

  • com.rokid.cxrlsample.activities.main.MainActivity
  • com.rokid.cxrlsample.activities.main.MainViewModel
  • com.rokid.cxrlsample.dataBean.CONSTANT.AUTH_REQUEST_CODE
Marcin Miazga