Monitoring on Android

Subscribing to Notifications

In order to receive document upload and processing notifications, a DocumentUploadObserver must subscribe to the SensibillSDK.

Note: notifications will only be provided if using the DocumentUploadManager (or capture flow) to initiate an upload.

An observer could either observe for the entirety of the SDK lifecycle, or just for the lifecycle of an Activity or Fragment:

// ========== Static Observer ==========
private val observer = DocumentUploadObserver.fromLambda { update ->
    // handle update as desired
}

// After starting the SDK
fun startObservingDocuments() {
    SensibillSDK.addDocumentUploadObserver(observer)
}

// Before stopping the SDK
fun stopObservingDocuments() {
    SensibillSDK.removeDocumentUploadObserver(observer)
}

// ========== Observe from an Activity ==========
class TempActivity : ComponentActivity() {
    private val observer = DocumentUploadObserver.fromLambda(this::onDocumentUploadUpdate)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent { DefaultPreview() }
        SensibillSDK.addDocumentUploadObserver(observer)
    }

    override fun onDestroy() {
        super.onDestroy()
        SensibillSDK.removeDocumentUploadObserver(observer)
    }

    private fun onDocumentUploadUpdate(update: DocumentUploadUpdateData) {
        // handle update as desired
    }
}
// ========== Static Observer ==========
public class SensibillSDKManager {
    private static DocumentUploadObserver documentUploadObserver = new DocumentUploadObserver() {
        @Override
        public void notify(@NonNull DocumentUploadUpdateData update) {
            // handle update as desired
        }
    };

    // After starting the SDK
    public static void startObservingDocumentUpdates() {
        SensibillSDK.getInstance().addDocumentUploadObserver(documentUploadObserver);
    }

    // Before stopping the SDK
    public static void stopObservingDocumentUpdates() {
        SensibillSDK.getInstance().removeDocumentUploadObserver(documentUploadObserver);
    }
}

// ========== Observe from an Activity ==========
public class TempActivity extends AppCompatActivity {

    private DocumentUploadObserver documentUploadObserver = new DocumentUploadObserver() {
        @Override
        public void notify(@NonNull DocumentUploadUpdateData update) {
            onDocumentUpdate(update);
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SensibillSDK.getInstance().addDocumentUploadObserver(documentUploadObserver);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SensibillSDK.getInstance().removeDocumentUploadObserver(documentUploadObserver);
    }

}

References:

Handling Notifications

Once a DocumentUploadObserver has been added to the SDK, it will receive all document upload updates until the observer has been removed. These updates can be used to monitor the status of a document’s upload and processing process. Along with identifying information of the document for which an update is being provided, a state, or status is provided with every update. Please view the reference documentation of DocumentStatus to see a diagram of the different states, as well as detailed explanations regarding what each state represents.

Info

The provided localId in a document upload update can be filtered for in order to track the upload process of one specific document

See the code example below for suggestions on what useful information can be derived from receiving an update.

private val observer = DocumentUploadObserver.fromLambda { update ->
    // The `localId` will be provided in the return value of `DocumentUploadManager.saveAndUploadDocuments`
    // and will remain unique and consistent throughout a document's uploading and processing process.
    // This id only exists on device and can be used for tracking a document during the upload process.
    val localId = update.localId

    // The `documentId` is determined by the server, and will be available when the status is at least `UPLOADED`.
    // Once a `documentId` exists, changes can be made to the document.  Also, after processing the document will
    // retain its `documentId` and it can be used to reference the document forevermore
    val documentId = update.documentId

    // The `status` part of the update contains the most up to date state of the document in its uploading and
    // processing process.  They can be handled in any way, however the most important states are the final states.
    // Three for various failure states, and one for a "fully uploaded and processed" success state.
    // See the linked reference documentation for details on the flow of states, and explanations on what each
    // state means.
    when (val status = update.status) {
        // Upload/processing in progress
        DocumentStatus.INITIALIZED -> TODO()
        DocumentStatus.UPLOADING -> TODO()
        DocumentStatus.UPLOADING_PAUSED_NO_INTERNET -> TODO()
        DocumentStatus.UPLOADED -> TODO()
        DocumentStatus.UPLOAD_FAILED_RECOVERABLE -> TODO()
        DocumentStatus.POLLING -> TODO()
        DocumentStatus.POLLING_TIMED_OUT -> TODO()
        DocumentStatus.POLLING_PAUSED_NO_INTERNET -> TODO()
        // Permanent Failure
        DocumentStatus.UPLOAD_FAILED_UNRECOVERABLE -> TODO()
        DocumentStatus.REACHED_MAX_RETRY_COUNT -> TODO()
        DocumentStatus.PROCESSED_FAILED -> TODO()
        // Document uploaded and processed
        DocumentStatus.PROCESSED_SUCCESS -> TODO()
    }
}
private DocumentUploadObserver documentUploadObserver = new DocumentUploadObserver() {
    @Override
    public void notify(@NonNull DocumentUploadUpdateData update) {
        // The `localId` will be provided in the return value of `DocumentUploadManager.saveAndUploadDocuments`
        // and will remain unique and consistent throughout a document's uploading and processing process.
        // This id only exists on device and can be used for tracking a document during the upload process.
        final long localId = update.getLocalId();

        // The `documentId` is determined by the server, and will be available when the status is at least `UPLOADED`.
        // Once a `documentId` exists, changes can be made to the document.  Also, after processing the document will
        // retain its `documentId` and it can be used to reference the document forevermore
        final String documentId = update.getDocumentId();

        // The `status` part of the update contains the most up to date state of the document in its uploading and
        // processing process.  They can be handled in any way, however the most important states are the final states.
        // Three for various failure states, and one for a "fully uploaded and processed" success state.
        // See the linked reference documentation for details on the flow of states, and explanations on what each
        // state means.
        final DocumentStatus status = update.getStatus();
        switch (status) {
            // Upload/processing in progress
            case INITIALIZED:
                break;
            case UPLOADING:
                break;
            case UPLOADING_PAUSED_NO_INTERNET:
                break;
            case UPLOADED:
                break;
            case UPLOAD_FAILED_RECOVERABLE:
                break;
            case POLLING:
                break;
            case POLLING_TIMED_OUT:
                break;
            case POLLING_PAUSED_NO_INTERNET:
                break;
            // Permanent Failure
            case UPLOAD_FAILED_UNRECOVERABLE:
                break;
            case REACHED_MAX_RETRY_COUNT:
                break;
            case PROCESSED_FAILED:
                break;
            // Document uploaded and processed
            case PROCESSED_SUCCESS:
                break;
        }
    }
};

References: