Skip to content

Initialization

How to perform the initialization of Document Reader SDK.

Overview

You can obtain a demo license here: https://licensing.regulaforensics.com

The initializeReader(Context context, DocReaderConfig config, IDocumentReaderInitCompletion completion) method initializes the Document Reader SDK. It accepts an instance of the DocReaderConfig class as a configuration object.

DocReaderConfig allows you to set the license for the Document Reader SDK and other configuration properties. For more information, please see the documentation for DocReaderConfig.

The initialization of the Document Reader SDK is performed fully offline, although by default the SDK attempts to access the licensing server. You can change this behavior by setting to false the setLicenseUpdate method of the DocReaderConfig instance.

Here is an example of how to perform initialization with the license that is put to the resources folder of the project:

//Reading the license from raw resource file
InputStream licInput = getResources().openRawResource(R.raw.regula);
int available = licInput.available();
byte[] license = new byte[available];
//noinspection ResultOfMethodCallIgnored
licInput.read(license);

DocumentReader.Instance().initializeReader(MainActivity.this, new DocReaderConfig(license), new IDocumentReaderInitCompletion() {
    @Override
    public void onInitCompleted(boolean success, Throwable error) {
        if (success) {
            //initialization successful
        } else {
            //Initialization was not successful
        }
    }
});
//Reading the license from raw resource file
val licInput = resources.openRawResource(R.raw.regula)
val available = licInput.available()
val license = ByteArray(available)

licInput.read(license)

DocumentReader.Instance().initializeReader(
    this@MainActivity, DocReaderConfig(license)
    ) { success, error_initializeReader ->
        if (success) {
            //initialization successful
        } else {
            //Initialization was not successful
        }
}

With Custom Database Path

Also, you can use a custom database path:

//Reading the license from raw resource file
InputStream licInput = getResources().openRawResource(R.raw.regula);
int available = licInput.available();
byte[] license = new byte[available];
//noinspection ResultOfMethodCallIgnored
licInput.read(license);

File dbFile = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),"db.dat");
byte[] dbData = FileUtils.readFileToByteArray(dbFile); // The array of bytes read from the file

DocumentReader.Instance().initializeReader(MainActivity.this, new DocReaderConfig(license, dbData), new IDocumentReaderInitCompletion() {
    @Override
    public void onInitCompleted(boolean success, Throwable error) {
        if (success) {
            //initialization successful
        } else {
            //Initialization was not successful
        }
    }
});
val dbFile = File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "db.dat")
val dbData: ByteArray = FileUtils.readFileToByteArray(dbFile) // The array of bytes read from the file

//Reading the license from raw resource file
val licInput = resources.openRawResource(R.raw.regula)
val available = licInput.available()
val license = ByteArray(available)

licInput.read(license)

DocumentReader.Instance().initializeReader(
    this@MainActivity, DocReaderConfig(license, dbData)
    ) { success, error_initializeReader ->
        if (success) {
            //initialization successful
        } else {
            //Initialization was not successful
        }
}
Back to top