# Migration Guide

## Migrating from v5.1 to v5.2

Errors are returned as [Throwable](https://developer.android.com/reference/java/lang/Throwable) now.

The database has to be updated along with the SDK as it's a part of it.

## Migrating from v5.0 to v5.1

{% hint style="info" %}
If you build an app with AndroidX, you have to enable the Jetifier plugin that automatically migrates existing third-party libraries to use AndroidX. [See how](https://developer.android.com/jetpack/androidx/migrate).
{% endhint %}

#### Database

The database has to be updated along with the SDK as it's a part of it.

#### Show scanner

If the below error was encountered, make sure that the right context had been passed to the [`showScanner()`](https://regulaforensics.gitbook.io/android/5.2-3/show-scanner) method, i.e. it has to be the context of the activity rather than the application.

```
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
```

#### Custom settings

Custom settings of the [Customization](https://regulaforensics.gitbook.io/android/5.2-3/custom-settings#customization) and [Functionality](https://regulaforensics.gitbook.io/android/5.2-3/custom-settings#functionality) class have to be set in the following way:

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().customization().edit().setStatus("Hello").applyImmediately(MainActivity.this);
DocumentReader.Instance().customization().edit().setShowHelpAnimation(true).apply();

DocumentReader.Instance().functionality().edit().setShowCaptureButton(true).apply();
DocumentReader.Instance().functionality().edit().setVideoCaptureMotionControl(true).apply();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().customization().edit().setStatus("Hello").applyImmediately(this@MainActivity)
DocumentReader.Instance().customization().edit().setShowHelpAnimation(true).apply()

DocumentReader.Instance().functionality().edit().setShowCaptureButton(true).apply()
DocumentReader.Instance().functionality().edit().setVideoCaptureMotionControl(true).apply()
```

{% endtab %}
{% endtabs %}

#### Completion

`DocumentReader.DocumentReaderCompletion` was changed to `IDocumentReaderCompletion`.

`DocumentReader.DocumentReaderInitCompletion` was changed to `IDocumentReaderInitCompletion`.

`DocumentReader.DocumentReaderPrepareCompletion` was changed to `IDocumentReaderPrepareCompletion`.

## Migrating from v4.2 to v5.0

#### Dependencies

Make sure that the new [`common`](https://maven.regulaforensics.com/RegulaDocumentReader/com/regula/documentreader/common/5.0.47/) library is added to the project and presented in the *External Libraries* list, otherwise, you may encounter the following errors:

```
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:8: AAPT: error: resource dimen/reg_img_button_size (aka com.regula.documentreader:dimen/reg_img_button_size) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:8: AAPT: error: resource dimen/reg_small_img_button_padding (aka com.regula.documentreader:dimen/reg_small_img_button_padding) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:8: AAPT: error: resource drawable/reg_close (aka com.regula.documentreader:drawable/reg_close) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:33: AAPT: error: resource style/PrimaryButton (aka com.regula.documentreader:style/PrimaryButton) not found. 
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:40: AAPT: error: resource style/PrimaryButton (aka com.regula.documentreader:style/PrimaryButton) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/help_bt_device_fragment.xml:47: AAPT: error: resource style/PrimaryButton (aka com.regula.documentreader:style/PrimaryButton) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:118: AAPT: error: resource dimen/reg_img_button_size (aka com.regula.documentreader:dimen/reg_img_button_size) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:118: AAPT: error: resource dimen/reg_small_img_button_padding (aka com.regula.documentreader:dimen/reg_small_img_button_padding) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:118: AAPT: error: resource drawable/reg_flash_off (aka com.regula.documentreader:drawable/reg_flash_off) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:132: AAPT: error: resource dimen/reg_img_button_size (aka com.regula.documentreader:dimen/reg_img_button_size) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:132: AAPT: error: resource dimen/reg_small_img_button_padding (aka com.regula.documentreader:dimen/reg_small_img_button_padding) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:132: AAPT: error: resource drawable/reg_camera_swap (aka com.regula.documentreader:drawable/reg_camera_swap) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:143: AAPT: error: resource dimen/reg_img_button_size (aka com.regula.documentreader:dimen/reg_img_button_size) not found. 
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:143: AAPT: error: resource drawable/reg_capture_activity_camera (aka com.regula.documentreader:drawable/reg_capture_activity_camera) not found.
/.../.gradle/caches/transforms-2/files-2.1/e8e5c59b760de91277d4b26b128becb5/res/layout/reg_activity_capture.xml:164: AAPT: error: resource dimen/reg_img_button_size (aka com.regula.documentreader:dimen/reg_img_button_size) not found.
```

#### Custom settings

[Custom settings](https://regulaforensics.gitbook.io/android/5.2-3/custom-settings) should be declared in the following way:

{% tabs %}
{% tab title="Java" %}

```java
DocumentReader.Instance().processParams().scenario = "Mrz";

DocumentReader.Instance().customization().setShowResultStatusMessages(true);

DocumentReader.Instance().rfidScenario().setMrz(accessKey);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DocumentReader.Instance().processParams().scenario = "Mrz"

DocumentReader.Instance().customization().isShowResultStatusMessages = true

DocumentReader.Instance().rfidScenario().setMrz(accessKey)
```

{% endtab %}
{% endtabs %}

#### Document Type Result

`documentType` is an array now that contains information about each page that has been read.

#### Text Result

Total text result status takes one of [`eCheckResult`](https://regulaforensics.gitbook.io/android/5.2-3/enumerations/echeckresult) enum values instead of [`eRPRM_FieldVerificationResult`](https://regulaforensics.gitbook.io/android/5.2-3/enumerations/erprm_fieldverificationresult).

#### Graphic Result

`GT_DOCUMENT_REAR` was removed and `GT_DOCUMENT_FRONT` was renamed to `GF_DOCUMENT_IMAGE` (see [`eGraphicFieldType`](https://regulaforensics.gitbook.io/android/5.2-3/enumerations/egraphicfieldtype) enum). In order to get the appropriate document side you should use the new property `pageIndex`, which is available in [`DocumentReaderGraphicResult`](https://regulaforensics.gitbook.io/android/5.2-3/results/description-of-results#graphic-result) class, e.g. pageIndex = 0 - it’s the first (front) side of the document, pageIndex = 1 - it’s the second (back) side of the document:

{% tabs %}
{% tab title="Java" %}

```java
// Get document side image (first page)
Bitmap documentImageFirstPage = results.getGraphicFieldImageByType(eGraphicFieldType.GF_DOCUMENT_IMAGE, -1, 0);
// Get document side image (second page)
Bitmap documentImageSecondPage = results.getGraphicFieldImageByType(eGraphicFieldType.GF_DOCUMENT_IMAGE, -1, 1);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// Get document side image (first page)
val documentImageFirstPage = results.getGraphicFieldImageByType(eGraphicFieldType.GF_PORTRAIT, -1, 0)
// Get document side image (second page)
val documentImageSecondPage = results.getGraphicFieldImageByType(eGraphicFieldType.GF_DOCUMENT_IMAGE, -1, 0)
```

{% endtab %}
{% endtabs %}
