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

## Table of contents

Javokhir's avatar
Javokhir committed
5
- [Important](#important)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
6
- [Getting started](#getting-started)
Javokhir's avatar
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
2.0.7  
Javokhir Savriev committed
10
- [Usage](#usage)
Javokhir's avatar
Javokhir committed
11
12
    - [Methods](#11-methods)
    - [Handling callbacks](#12-handling-callbacks)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
13
14
- [SDK error codes](#sdk-error-codes)
- [Localization](#localization)
Javokhir's avatar
2.1.1    
Javokhir committed
15
- [Custom Organization Details](#custom-organization-details)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
16

Javokhir's avatar
Javokhir committed
17
18
19
20
21
## Important

**Note:** When you update the version of MyID SDK in your application, check the version of the
libraries in [dependencies](#12-setup-myid-android-sdk) and update them too!

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
22
23
24
25
26
27
28
29
30
31
32
## 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`
Javokhir's avatar
2.1.1    
Javokhir committed
33
- `targetSdkVersion = 33`
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
34
35
- `android.useAndroidX = true`

Javokhir's avatar
Javokhir committed
36
37
38
39
40
``` gradle
compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
}
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
41
42
43
44
45
```

- myid-sdk-***.aar, has been provided to you, it contains SDK public interface and implementation.
  Archive name contains ever increasing release version number.

Javokhir's avatar
Javokhir committed
46
### 1.2 Setup MyID Android SDK
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
47
48

Create new project in AndroidStudio. Inside mobile application folder create new folder to store SDK
Javokhir's avatar
Javokhir committed
49
libraries (For example libs) and copy MyID SDK provided libraries.
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
50
51
52
53

Add reference to library to module **_build.gradle_**:

``` gradle
Javohir Savriy's avatar
Javohir Savriy committed
54
implementation(files("libs/myid-sdk-2.1.3-release.aar"))
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
55
```
Javokhir's avatar
Javokhir committed
56

Javohir Savriy's avatar
Javohir Savriy committed
57
58
**Note:** You can get `myid-sdk-2.1.3-release.aar` file
from [here](android-sample/app/libs/myid-sdk-2.1.3-release.aar)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
59

Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
60
After synchronization, You should be able to access to SDK classes from your source code.
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
61

Javokhir's avatar
Javokhir committed
62
MyID Android SDK also requires following libraries to be added:
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
63
64

``` gradle
Javokhir's avatar
Javokhir committed
65
dependencies {
Javohir Savriy's avatar
Javohir Savriy committed
66
    implementation(files("libs/myid-sdk-2.1.3-release.aar"))
Javokhir's avatar
2.1.1    
Javokhir committed
67

Javokhir's avatar
Javokhir committed
68
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
69

Javokhir's avatar
Javokhir committed
70
71
72
73
74
    implementation("androidx.core:core-ktx:1.9.0")
    implementation("androidx.appcompat:appcompat:1.5.1")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.1")
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
75

76
    def cameraVersion = "1.3.0-alpha01"
Javokhir's avatar
Javokhir committed
77
78
79
    implementation("androidx.camera:camera-camera2:$cameraVersion")
    implementation("androidx.camera:camera-lifecycle:$cameraVersion")
    implementation("androidx.camera:camera-view:$cameraVersion")
80
81
82
83
84
    
    implementation("io.ktor:ktor-client-android:2.1.2")
    implementation("io.sentry:sentry-android:6.7.0-alpha.1")
    
    // Use these dependencies if your app supports Google Play Services
Javokhir's avatar
Javokhir committed
85
86
87
    implementation("com.google.android.gms:play-services-mlkit-face-detection:17.1.0")
    implementation("com.google.android.gms:play-services-mlkit-text-recognition:18.0.2")
    implementation("com.google.android.gms:play-services-mlkit-barcode-scanning:18.1.0")
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
88

89
90
91
92
    // Use these dependencies if your app doesn't support Google Play Services
    implementation("com.google.mlkit:face-detection:16.1.5")
    implementation("com.google.mlkit:text-recognition:16.0.0-beta6")
    implementation("com.google.mlkit:barcode-scanning:17.0.2")
Javokhir's avatar
Javokhir committed
93
}
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
94
95
96
97
98
99
100
101
102
103
104
105
106
```

### 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

Javohir Savriy's avatar
Javohir Savriy committed
107
108
### With Activity Result API

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
109
``` kotlin
Javohir Savriy's avatar
Javohir Savriy committed
110
class ExampleActivity : AppCompatActivity(), MyIdResultListener {
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
111

Javokhir's avatar
Javokhir committed
112
    private val myIdClient = MyIdClient()
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
113
114
115
116
117
118
119

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

    private fun startMyId() {
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
120
121
122
123
124
        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
            logo = R.drawable.image_logo
        )
        
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
125
126
127
        val myIdConfig = MyIdConfig.builder(clientId = /* Your client id */)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
128
            .withSdkHash(sdkHash)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
129
            .withExternalId(externalId)
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
130
            .withThreshold(threshold)
Javokhir's avatar
Javokhir committed
131
            .withBuildMode(MyIdBuildMode.PRODUCTION)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
132
            .withEntryType(MyIdEntryType.AUTH)
Javokhir's avatar
Javokhir committed
133
134
            .withLocale(Locale("en"))
            .withCameraShape(MyIdCameraShape.CIRCLE)
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
135
            .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
136
137
138
139
140
141
142
143
144
145
146
            .withPhoto(false)
            .build()

        val intent = client.createIntent(activity = this, myIdConfig = myIdConfig)
        result.launch(intent)
    }

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

Javohir Savriy's avatar
Javohir Savriy committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
192
193
### With `onActivityResult` method

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

    private val myIdClient = MyIdClient()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        startMyId()
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        myIdClient.handleActivityResult(resultCode, this)
    }

    private fun startMyId() {
        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
            logo = R.drawable.image_logo
        )
        
        val myIdConfig = MyIdConfig.builder(clientId = /* Your client id */)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withSdkHash(sdkHash)
            .withExternalId(externalId)
            .withThreshold(threshold)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .withEntryType(MyIdEntryType.AUTH)
            .withLocale(Locale("en"))
            .withCameraShape(MyIdCameraShape.CIRCLE)
            .withOrganizationDetails(organizationDetails)
            .withPhoto(false)
            .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.
        */
        myIdClient.startActivityForResult(this, 1, myIdConfig)
    }
}
```

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
194
195
196
197
198
199
### 1.1 Methods

Method | Notes | Default
--- | --- | ---
`withPassportData(value: String)` | Passport serial number or PINFL data | Optional
`withBirthDate(value: String)` | Date of birth in. Format: `dd.MM.yyyy` | Optional
200
`withSdkHash(value: String)` | 32 characters long string | Optional
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
201
`withExternalId(value: String)` | 36 characters long. Should match with UUID4 regex | Optional
Javohir Savriy's avatar
Javohir Savriy committed
202
`withThreshold(value: Float)` | The value can be in the range of `0.50` - `0.99` | 0.50
Javokhir's avatar
Javokhir committed
203
204
205
206
`withBuildMode(value: MyIdBuildMode)` | Build mode | MyIdBuildMode.PRODUCTION
`withEntryType(value: MyIdEntryType)` | Customizing the SDK Entry types | MyIdEntryType.AUTH
`withLocale(value: Locale)` | To set a specific locale | Locale("uz")
`withCameraShape(value: MyIdCameraShape)` | To set a specific camera shape | MyIdCameraShape.CIRCLE
Javohir Savriy's avatar
Javohir Savriy committed
207
`withOrganizationDetails(value: OrganizationDetails)` | Custom Organization Details | Optional
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
208
209
`withPhoto(value: Boolean)` | Return SDK face bitmap | false

210
**Note 1.1.** You can customize the screen for entering passport data and date of birth in your
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
211
212
213
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.

214
215
216
217
218
219
220
221
**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.
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
222
223
224
225

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

226
227
228
229
**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).
Javokhir's avatar
Javokhir committed
230

231
**Note 1.6.** `MyIdCameraShape` contains **[CIRCLE](images/screen03.jpg)**
Javokhir's avatar
Javokhir committed
232
and **[ELLIPSE](images/screen04.jpg)** types.
Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
233

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
234
235
236
### 1.2 Handling callbacks

```kotlin
Javokhir's avatar
Javokhir committed
237
val myIdResultListener: MyIdResultListener = object : MyIdResultListener {
Javokhir's avatar
2.1.1    
Javokhir committed
238
239
    override fun onSuccess(result: MyIdResult) {
        // Get face bitmap and result code
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
240

Javokhir's avatar
2.1.1    
Javokhir committed
241
242
243
244
        val bitmap = result.bitmap
        val code = result.code
        val comparison = result.comparison
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
245

Javokhir's avatar
2.1.1    
Javokhir committed
246
247
248
    override fun onUserExited() {
        // User left the SDK
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
249

Javokhir's avatar
2.1.1    
Javokhir committed
250
251
    override fun onError(e: MyIdException) {
        // Get error message and code:
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
252

Javokhir's avatar
2.1.1    
Javokhir committed
253
254
255
        val message = e.message
        val code = e.code
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
256
257
258
259
260
}
```

| Attribute     |    Notes    |
| -----|-------|
Javohir Savriy's avatar
Javohir Savriy committed
261
| `onSuccess` | `MyIdResult` contains information about the face captures made during the flow, result code and comparison value. |
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
262
263
264
265
266
267
268
269
| `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.

Javokhir's avatar
Javokhir committed
270
271
272
273
274
275
276
277
278
279
| Code |      Error message
|:----:|:-------------
|  2   |  Паспортные данные введены неправильно
|  3   |  Не удалось подтвердить жизненность
|  4   |  Не удалось распознать
|  5   |  Внешний сервис недоступен или работает некорректно
|  6   |  Запрашиваемый пользовател скончался
|  7   |  Фото с ресурсов не получено
|  8   |  Внутренняя ошибка MyID
|  9   |  Срок выполнения задачи истек
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|  10  |  Срок ожидания задачи в очереди истек
|  11  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  12  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  13  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  14  |  Не удалось подтвердить жизненность. Некорректная фотография
|  15  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  16  |  Сервис MyID не может обработать запрос. Попробуйте повторить позже
|  17  |  Не удалось распознать. Некорректная фотография
|  18  |  Сервис проверки жизненности не может обработать запрос
|  19  |  Сервис распознования не может обработать запрос
|  20  |  Размытая фотография
|  21  |  Лицо не полностью изображено
|  22  |  Обнаружено несколько лиц
|  23  |  Представленное изображение в градациях серого, требуется цветное изображение
|  24  |  Обнаружены затемненные очки
Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
295
|  25  |  Тип фотографии не поддерживается
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
296
|  26  |  Глаза закрыты либо не видны
Javokhir's avatar
Javokhir committed
297
298
299
300
301
302
|  27  |  Обнаружено вращение головы
|  28  |  Не удалось обнаружить все ориентиры
| 101  |  Непредвиденная ошибка
| 102  |  Доступ к камере запрещен
| 103  |  Ошибка при получении данных с сервера
| 120  |  Размытое фото обнаружено в SDK
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
303
304
305

## Localization

Javokhir's avatar
Javokhir committed
306
The MyID Android SDK supports translations for the following languages:
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
307
308
309
310
311

- Uzbek      (uz) 🇺🇿
- English    (en) 🇬🇧
- Russian    (ru) 🇷🇺

Javokhir's avatar
Javokhir committed
312
By default, the Uzbek language is used. However, you can also call the `withLocale(Locale)`
Javokhir's avatar
2.1.1    
Javokhir committed
313
method of the `MyIdConfig.Builder` configuration to set the language.
Javohir Savriy's avatar
Javohir Savriy committed
314
315
316

## Custom Organization Details

Javokhir's avatar
Javokhir committed
317
318
319
320
321
322
323
324
325
You can customize the SDK, for it to match your organization's brand book, by
providing `OrganizationDetails` object to `withOrganizationDetails` method. The object allows you to
customize following fields:

- *phoneNumber* - by default 712022202, which is MyID's call center. If you would like the customer
  to call your own call center, you can display your own phone number on the error screen, by
  providing it in this field ([sample](images/screen01.jpg)).
- *logo* - the drawable asset, that will be displayed on the input screen. If you would like to
  display your own logo on the top of the screen, this is the place to provide it. Make sure it fits
Javohir Savriy's avatar
Javohir Savriy committed
326
  the imageView element, which has the *240x60* size.