Quick Setup
After following the install instructions you are ready to launch the SDK. This quick setup guide will go over the two basic ways of launching the SDK.
Launching via Composition
The Ozone SDK is built from the ground up to work well with Jetpack Compose. While we provide an activity for legacy apps, the activity merely draws an OzoneView as its content and returns the results of the callbacks via the activity's response intent. If your implementation already uses compose we strongly recommend you use this approach instead of the activity.
-
Implement the following functions in the code from which you plan to call the composition:
private fun handleSuccess(result: OzoneResultData)
private fun handleError(error: SmartCaptureException)
private fun handleCancel() -
Create an
OzoneInputDataobject like such (see Unlocking the NFC chip for more info):val ozoneInputData = OzoneInputData(
documentNumber = documentNumber,
dateOfBirth = dob,
dateOfExpiration = doe
) -
Within a
@Composablefunction call theOzoneViewcomposition, passing in the input data and each of the functions above. We recommend wrapping it in theSmartCaptureUiThemeas that is what it is currently designed for and tested with (see theme documentation for more info):SmartCaptureUiTheme {
OzoneView(
inputData = ozoneInputData,
onSuccessCallback = ::handleSuccess,
onErrorCallback = ::handleError,
onCancelCallback = ::handleCancel
)
} -
That's it. If you want to know more details about what the composable is doing behind the scenes or how to configure it further, check out the OzoneView section. To see references for classes mentioned above, see the references. For error codes check out the general references.
Launching via Activity
-
Register an
ActivityResultLauncherthat will handle the result from this activity.private val ozoneLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
when (result.resultCode) {
RESULT_OK -> {
ozoneResult = OzoneUiActivity.getReadNfcData()
//use the ozone result
}
RESULT_CANCELED -> {
//handle user cancellation
}
else -> {
val error = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
result.data?.getSerializableExtra(RESULT_FAIL_EXTRA_ERROR,
SmartCaptureException::class.java)
} else {
@Suppress("DEPRECATION")
result.data?.getSerializableExtra(RESULT_FAIL_EXTRA_ERROR) as SmartCaptureException?
}
//handle the error
}
}
}Note: Error Codes can be found in the general references section.
-
Start the activity using the
ActivityResultLauncheryou created in the previous step, providing the information needed to unlock the NFC chip.val intent = Intent(this, OzoneUiActivity::class.java)
intent.putExtra(INPUT_DATA, OzoneInputData(
documentNumber = documentNumber,
dateOfBirth = dob,
dateOfExpiration = doe
))
ozoneLauncher.launch(intent)