README.md 10.1 KB
Newer Older
Javokhir Savriev's avatar
Javokhir Savriev committed
1
2
3
4
# MyID Android SDK

## Table of contents

Javohir Savriy's avatar
Javohir Savriy committed
5
- [Changelog](CHANGELOG.md)
Javokhir Savriev's avatar
Javokhir Savriev committed
6
- [Getting started](#getting-started)
Javokhir's avatar
2.2.2    
Javokhir committed
7
8
9
  - [Before you begin](#11-before-you-begin)
  - [Setup MyID Android SDK](#12-setup-myid-android-sdk)
  - [Permissions](#13-permissions)
Javokhir Savriev's avatar
Javokhir Savriev committed
10
- [Usage](#usage)
Javokhir's avatar
2.2.2    
Javokhir committed
11
12
  - [Methods](#11-methods)
  - [Handling callbacks](#12-handling-callbacks)
Javokhir Savriev's avatar
Javokhir Savriev committed
13
- [SDK error codes](#sdk-error-codes)
Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
14
- [UI customization](CUSTOMIZATION.md)
Javokhir Savriev's avatar
Javokhir Savriev committed
15
16
17
18
19
20
21
22
23
24
25
26

## Getting started

### 1.1 Before you begin

Install or update Android Studio to its latest version.

The SDK supports API level 21 and above

Make sure that your app meets the following requirements:

- `minSdkVersion = 21`
Javohir Savriy's avatar
Javohir Savriy committed
27
- `targetSdkVersion = 34`
Javokhir's avatar
2.3.4    
Javokhir committed
28
- `Kotlin = 1.8.22+`
Javokhir Savriev's avatar
Javokhir Savriev committed
29
30
31
32
33
34
35
36
37
38
39
- `android.useAndroidX = true`

``` gradle
compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
}
```

### 1.2 Setup MyID Android SDK

Javohir Savriy's avatar
Javohir Savriy committed
40
41
42
#### Step 1: Add the Repository

First, add the Artifactory repository to the repositories block of your module's **_build.gradle_** file:
Javokhir Savriev's avatar
Javokhir Savriev committed
43

Javohir Savriy's avatar
Javohir Savriy committed
44
45
46
47
```gradle
repositories {
  maven { url "https://artifactory.aigroup.uz:443/artifactory/myid" }
}
Javohir Savriy's avatar
Javohir Savriy committed
48
49
50
```

#### Step 2: Add the Dependency
Javokhir Savriev's avatar
Javokhir Savriev committed
51

Javohir Savriy's avatar
Javohir Savriy committed
52
53
54
Next, add the SDK dependency to the dependencies block:

```gradle
Javokhir Savriev's avatar
Javokhir Savriev committed
55
dependencies {
Javohir Savriy's avatar
Javohir Savriy committed
56
  implementation("uz.myid.sdk.capture:myid-capture-sdk:2.3.7")
Javokhir Savriev's avatar
Javokhir Savriev committed
57
58
59
}
```

Javohir Savriy's avatar
Javohir Savriy committed
60
61
62
63
If you are using Huawei devices, Flutter or an environment that does not support Google Play Services, use the bundled version of the SDK:

```gradle
dependencies {
Javohir Savriy's avatar
Javohir Savriy committed
64
  implementation("uz.myid.sdk.capture:myid-capture-sdk-bundled:2.3.7")
Javohir Savriy's avatar
Javohir Savriy committed
65
66
67
}
```

Javohir Savriy's avatar
Javohir Savriy committed
68
69
After synchronization, You should be able to access to SDK classes from your source code.

Javokhir Savriev's avatar
Javokhir Savriev committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
### 1.3 Permissions

Add following lines to the **_AndroidManifest.xml_**:

``` xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
```

## Usage

### With Activity Result API

``` kotlin
class ExampleActivity : AppCompatActivity(), MyIdResultListener {

Javokhir's avatar
2.2.7    
Javokhir committed
86
    private val client = MyIdClient()
Javokhir Savriev's avatar
Javokhir Savriev committed
87
88
89
90
91
92
93

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        startMyId()
    }

    private fun startMyId() {
Javokhir's avatar
2.2.7    
Javokhir committed
94
        val config = MyIdConfig.builder(clientId = /* Your client id */)
Javokhir's avatar
2.2.2    
Javokhir committed
95
            .withClientHash(/* Your clientHash */, /* Your clientHashId */)
Javokhir Savriev's avatar
Javokhir Savriev committed
96
97
98
99
100
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .build()

Javokhir's avatar
2.2.7    
Javokhir committed
101
        val intent = client.createIntent(activity = this, config)
Javokhir Savriev's avatar
Javokhir Savriev committed
102
103
104
105
106
107
108
109
110
111
112
113
        result.launch(intent)
    }

    private val result = takeUserResult(listener = this)
}
```

### With `onActivityResult` method

``` kotlin
class ExampleActivity : AppCompatActivity(), MyIdResultListener {

Javokhir's avatar
2.2.7    
Javokhir committed
114
    private val client = MyIdClient()
Javokhir Savriev's avatar
Javokhir Savriev committed
115
116
117
118
119
120
121
122

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        startMyId()
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
Javokhir's avatar
2.2.7    
Javokhir committed
123
        client.handleActivityResult(resultCode, this)
Javokhir Savriev's avatar
Javokhir Savriev committed
124
125
126
    }

    private fun startMyId() {
Javokhir's avatar
2.2.7    
Javokhir committed
127
        val config = MyIdConfig.builder(clientId = /* Your client id */)
Javokhir's avatar
2.2.2    
Javokhir committed
128
            .withClientHash(/* Your clientHash */, /* Your clientHashId */)
Javokhir Savriev's avatar
Javokhir Savriev committed
129
130
131
132
133
134
135
136
137
138
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .build()

        /*
           Start the flow. 1 should be your request code (customize as needed).
           Must be an Activity or Fragment (support library).
           This request code will be important for you on onActivityResult() to identify the MyIdResultListener.
        */
Javokhir's avatar
2.2.7    
Javokhir committed
139
        client.startActivityForResult(this, 1, config)
Javokhir Savriev's avatar
Javokhir Savriev committed
140
141
142
143
144
145
146
147
    }
}
```

### 1.1 Methods

Method | Notes | Default
--- | --- | ---
Javokhir's avatar
2.2.2    
Javokhir committed
148
`withClientHash(clientHash: String, clientHashId: String)` | Provided by MyID sales team | Mandatory, if using withEntryType(MyIdEntryType.AUTH)
Javokhir Savriev's avatar
Javokhir Savriev committed
149
`withPassportData(value: String)` | Passport serial number or PINFL data | Optional
Javokhir's avatar
2.2.7    
Javokhir committed
150
151
152
`withBirthDate(value: String)` | Date of birth. Format: `dd.MM.yyyy` | Optional
`withMinAge(value: Int)` | To set a specific minimum age to use MyID service | 16
`withSdkHash(value: String)` | 32 characters long string (Note 1.2) | Optional
Javohir Savriy's avatar
Javohir Savriy committed
153
`withExternalId(value: String)` | 36 characters long. Should match with UUID4 regex (Note 1.3) | Optional
154
`withThreshold(value: Float)` | The value can be in the range of `0.55` - `0.99` | 0.55
Javokhir's avatar
2.2.7    
Javokhir committed
155
156
`withBuildMode(value: MyIdBuildMode)` | Build mode (Note 1.4) | MyIdBuildMode.PRODUCTION
`withEntryType(value: MyIdEntryType)` | Customizing the SDK Entry types (Note 1.5) | MyIdEntryType.AUTH
Javokhir Savriev's avatar
Javokhir Savriev committed
157
158
`withResidency(value: MyIdResidentType)` | To set a specific resident type | MyIdResidentType.RESIDENT
`withLocale(value: Locale)` | To set a specific locale | Locale("uz")
Javokhir's avatar
2.2.7    
Javokhir committed
159
`withCameraShape(value: MyIdCameraShape)` | To set a specific camera shape (Note 1.6) | MyIdCameraShape.CIRCLE
Javohir Savriy's avatar
Javohir Savriy committed
160
`withResolution(value: MyIdResolution)` | To set a specific camera resolution | MyIdResolution.RESOLUTION_480
Javokhir's avatar
2.2.7    
Javokhir committed
161
`withScreenOrientation(value: MyIdScreenOrientation)` | To set a specific screen orientation | MyIdScreenOrientation.FULL
Javokhir Savriev's avatar
Javokhir Savriev committed
162
`withImageFormat(value: MyIdImageFormat)` | To set a specific image format | MyIdImageFormat.PNG
Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
163
`withOrganizationDetails(value: MyIdOrganizationDetails)` | Custom Organization Details | Optional
Javokhir Savriev's avatar
Javokhir Savriev committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

**Note 1.1.** You can customize the screen for entering passport data and date of birth in your
application, in which case you can pass these parameters during initialization to the SDK, otherwise
the SDK requires the input of passport data and date of birth for user identification.

**Note 1.2.** If the `sdk_hash` is empty, blank or string with length other than 32 has been
provided, we will continue showing the credentials screen.

**Note 1.3.** If the `externalId` is not empty, has a length of 36 characters and corresponds to the
regular expression UUID4, we will display a [recommendation](images/screen01.jpg) screen in case the
sdk detects a blurry photo.

**Note 1.4.** `MyIdBuildMode` contains **DEBUG** and **PRODUCTION** modes.

- **DEBUG** is used to sandbox.
- **PRODUCTION** is used to production.

**Note 1.5.** `MyIdEntryType` contains **AUTH** and **FACE** types.

- **AUTH** is used to identify the user through the MyID services.
- **FACE** is used to detect a face and returns a picture (bitmap).

**Note 1.6.** `MyIdCameraShape` contains **[CIRCLE](images/screen03.jpg)**
and **[ELLIPSE](images/screen04.jpg)** types.

### 1.2 Handling callbacks

```kotlin
Javokhir's avatar
2.2.7    
Javokhir committed
192
val resultListener: MyIdResultListener = object : MyIdResultListener {
Javokhir's avatar
2.2.2    
Javokhir committed
193
194
  override fun onSuccess(result: MyIdResult) {
    // Get face bitmap and result code
Javokhir Savriev's avatar
Javokhir Savriev committed
195

Javokhir's avatar
Javokhir committed
196
    val bitmap = result.getGraphicFieldImageByType(MyIdGraphicFieldType.FACE_PORTRAIT)
Javokhir's avatar
2.2.2    
Javokhir committed
197
198
199
    val code = result.code
    val comparison = result.comparison
  }
Javokhir Savriev's avatar
Javokhir Savriev committed
200

Javokhir's avatar
2.2.2    
Javokhir committed
201
202
203
  override fun onUserExited() {
    // User left the SDK
  }
Javokhir Savriev's avatar
Javokhir Savriev committed
204

Javokhir's avatar
2.2.2    
Javokhir committed
205
206
  override fun onError(e: MyIdException) {
    // Get error message and code:
Javokhir Savriev's avatar
Javokhir Savriev committed
207

Javokhir's avatar
2.2.2    
Javokhir committed
208
209
210
    val message = e.message
    val code = e.code
  }
Javokhir Savriev's avatar
Javokhir Savriev committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
}
```

| Attribute     |    Notes    |
| -----|-------|
| `onSuccess` | `MyIdResult` contains information about the face captures made during the flow, result code and comparison value. |
| `onUserExited` | User left the SDK flow without completing it. |
| `onError` | Some error happened. `MyIdException` contains information about the error message and code |

## SDK error codes

The error code in the following list may appear during the call of SDK. The list below is for your
reference.

| Code |      Error message
|:----:|:-------------
|  2   |  Паспортные данные введены неправильно
|  3   |  Не удалось подтвердить жизненность
|  4   |  Не удалось распознать
|  5   |  Внешний сервис недоступен или работает некорректно
|  6   |  Запрашиваемый пользовател скончался
|  7   |  Фото с ресурсов не получено
|  8   |  Внутренняя ошибка MyID
|  9   |  Срок выполнения задачи истек
|  10  |  Срок ожидания задачи в очереди истек
|  11  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  12  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  13  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  14  |  Не удалось подтвердить жизненность. Некорректная фотография
|  15  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  16  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  17  |  Не удалось распознать. Некорректная фотография
|  18  |  Сервис проверки жизненности не может обработать запрос
|  19  |  Сервис распознования не может обработать запрос
|  20  |  Размытая фотография
|  21  |  Лицо не полностью изображено
|  22  |  Обнаружено несколько лиц
|  23  |  Представленное изображение в градациях серого, требуется цветное изображение
|  24  |  Обнаружены затемненные очки
|  25  |  Тип фотографии не поддерживается
|  26  |  Глаза закрыты либо не видны
|  27  |  Обнаружено вращение головы
|  28  |  Не удалось обнаружить все ориентиры
| 101  |  Непредвиденная ошибка
| 102  |  Доступ к камере запрещен
| 103  |  Ошибка при получении данных с сервера
Javohir Savriy's avatar
Javohir Savriy committed
257
| 120  |  Размытое фото обнаружено в SDK