Start Document Detection

Starting Activity

After creating the DocumentDetector, start the DocumentDetectorActivity by passing this object as a parameter via extra intent:

Example

    private fun startDocumentDetector(upload: Boolean = false) {
        val documentDetector = buildDocumentDetector(upload)
        val intent = Intent(this, DocumentDetectorActivity::class.java)
        intent.putExtra(DocumentDetector.PARAMETER_NAME, documentDetector)
        startActivityForResult(intent, REQUEST_CODE)
    }

Getting the result

To get the DocumentDetectorResult object, which contains the captures taken by the SDK, override the onActivityResult method in the same Activity that you started the DocumentDetectorActivity.

More details about error responses in the SDK Response section

Example

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            val result = data?.getSerializableExtra(
                DocumentDetectorResult.PARAMETER_NAME
            ) as DocumentDetectorResult

            if (!result.wasSuccessful()) {
                result.sdkFailure?.let {
                    onSdkFailure(it)
                }
                return
            }

            println("DocumentDetectorResult: $result")
        } else {
            println("The user canceled the operation")
        }
        super.onActivityResult(requestCode, resultCode, data)
    }

    private fun onSdkFailure(sdkFailure: SDKFailure?) {
        when (sdkFailure) {
            is InvalidTokenReason -> {
                println("SDKFailure: The token entered as a parameter is not valid, please revise it")
            }
            is PermissionReason -> {
                println("SDKFailure: The user did not grant the necessary permissions")
            }
            is AvailabilityReason -> {
                println("SDKFailure: Instructions are sent in: ${sdkFailure.message}")
            }
            is NetworkReason -> {
                println("SDKFailure: There was a problem with the internet connection")
            }
            is ServerReason -> {
                println("SDKFailure: There was a problem in any communication with the CAF servers, let us know!")
            }
            is SecurityReason -> {
                println("SDKFailure: There was a security problem on the user's device")
            }
            is StorageReason -> {
                println("SDKFailure: There was a problem with the internal storage of the user's device")
            }
            is LibraryReason -> {
                println("SDKFailure: There was a problem with the internal library")
            }
            else -> {
                println("SDKFailure: Unknown reason")
            }
        }
    }

Last updated

Logo

2023 © Caf. - All rights reserved