README.md 10.1 KB
Newer Older
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
1
2
3
4
5
6
7
8
9
10
11
12
13
# MyId Android SDK

## Table of contents

- [Getting started](#getting-started)
  - [Before you begin](#11-before-you-begin)
  - [Setup MyId Android SDK](#12-setup-myid-android-sdk)
  - [Permissions](#13-permissions)
- [Usage](#usage)
  - [Methods](#11-methods)
  - [Handling callbacks](#12-handling-callbacks)
- [SDK error codes](#sdk-error-codes)
- [Localization](#localization)
Javokhir's avatar
2.1.1    
Javokhir committed
14
- [Custom Organization Details](#custom-organization-details)
Javokhir Savriev's avatar
2.0.7  
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`
Javokhir's avatar
2.1.1    
Javokhir committed
27
- `targetSdkVersion = 33`
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
- `android.useAndroidX = true`

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

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

### 1.2 Setup MyId Android SDK

Create new project in AndroidStudio. Inside mobile application folder create new folder to store SDK
libraries (For example libs) and copy MyId SDK provided libraries.

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

``` gradle
Javokhir's avatar
2.1.1    
Javokhir committed
48
implementation(files("libs/myid-sdk-2.1.1-release.aar"))
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
49
```
Javokhir's avatar
2.1.1    
Javokhir committed
50
**Note:** You can get `myid-sdk-2.1.1-release.aar` file from [here](app/libs/myid-sdk-2.1.1-release.aar)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
51

Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
52
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
53
54
55
56

MyId Android SDK also requires following libraries to be added:

``` gradle
Javokhir's avatar
2.1.1    
Javokhir committed
57
58
implementation(files("libs/myid-sdk-2.1.1-release.aar"))

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

Javokhir's avatar
2.1.1    
Javokhir committed
61
62
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.5.1")
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
63
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
64
65
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
66

Javokhir's avatar
2.1.1    
Javokhir committed
67
def cameraVersion = "1.2.0-rc01"
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
68
69
70
71
implementation("androidx.camera:camera-camera2:$cameraVersion")
implementation("androidx.camera:camera-lifecycle:$cameraVersion")
implementation("androidx.camera:camera-view:$cameraVersion")

Javokhir's avatar
2.1.1    
Javokhir committed
72
73
74
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
75
76

implementation("io.ktor:ktor-client-android:2.0.1")
Javokhir's avatar
2.1.1    
Javokhir committed
77
implementation("io.sentry:sentry-android:6.7.0-alpha.1")
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
```

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

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

    private val client: MyIdClient = MyIdClient()

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

    private fun startMyId() {
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
102
103
104
105
106
        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
            logo = R.drawable.image_logo
        )
        
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
107
108
109
110
        val myIdConfig = MyIdConfig.builder(clientId = /* Your client id */)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withExternalId(externalId)
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
111
            .withThreshold(threshold)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
112
            .withEntryType(MyIdEntryType.AUTH)
Javohir Savriy's avatar
2.0.9    
Javohir Savriy committed
113
            .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
114
            .withBuildMode(MyIdBuildMode.PRODUCTION)
Javokhir's avatar
2.1.1    
Javokhir committed
115
            .withLocale(MyIdLocale.UZ)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
            .withPhoto(false)
            .build()

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

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

### 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
`withExternalId(value: String)` | 36 characters long. Should match with UUID4 regex | Optional
Javohir Savriy's avatar
Javohir Savriy committed
134
`withThreshold(value: Float)` | The value can be in the range of `0.50` - `0.99` | 0.50
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
135
`withEntryType(value: MyIdEntryType)` | Customizing the SDK. Entry types: AUTH, FACE | MyIdEntryType.AUTH
Javohir Savriy's avatar
Javohir Savriy committed
136
`withOrganizationDetails(value: OrganizationDetails)` | Custom Organization Details | Optional
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
137
`withBuildMode(value: MyIdBuildMode)` | Build mode: DEBUG, PRODUCTION | MyIdBuildMode.PRODUCTION
Javokhir's avatar
2.1.1    
Javokhir committed
138
`withLocale(value: MyIdLocale)` | To set a specific language | MyIdLocale.UZ
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
`withPhoto(value: Boolean)` | Return SDK face bitmap | false

**Note 1.1.** `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.2.** 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.3.** `MyIdBuildMode` contains **DEBUG** and **PRODUCTION** modes.

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

Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
155
156
**Note 1.4.** 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.

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
157
158
159
160
### 1.2 Handling callbacks

```kotlin
val resultListener: MyIdResultListener = object : MyIdResultListener {
Javokhir's avatar
2.1.1    
Javokhir committed
161
162
    override fun onSuccess(result: MyIdResult) {
        // Get face bitmap and result code
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
163

Javokhir's avatar
2.1.1    
Javokhir committed
164
165
166
167
        val bitmap = result.bitmap
        val code = result.code
        val comparison = result.comparison
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
168

Javokhir's avatar
2.1.1    
Javokhir committed
169
170
171
    override fun onUserExited() {
        // User left the SDK
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
172

Javokhir's avatar
2.1.1    
Javokhir committed
173
174
    override fun onError(e: MyIdException) {
        // Get error message and code:
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
175

Javokhir's avatar
2.1.1    
Javokhir committed
176
177
178
        val message = e.message
        val code = e.code
    }
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
179
180
181
182
183
}
```

| Attribute     |    Notes    |
| -----|-------|
Javohir Savriy's avatar
Javohir Savriy committed
184
| `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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
| `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  |  Обнаружены затемненные очки
Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
218
|  25  |  Тип фотографии не поддерживается
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
219
|  26  |  Глаза закрыты либо не видны
Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
220
|  101  |  Непредвиденная ошибка
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
221
222
|  102  |  Доступ к камере запрещен
|  103  |  Ошибка при получении данных с сервера
Javokhir Savriev's avatar
2.0.8    
Javokhir Savriev committed
223
|  120  |  Размытое фото обнаружено в SDK
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
224
225
226
227
228
229
230
231
232

## Localization

The MyId Android SDK supports translations for the following languages:

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

Javokhir's avatar
2.1.1    
Javokhir committed
233
234
By default, the Uzbek language is used. However, you can also call the `withLocale(MyIdLocale)`
method of the `MyIdConfig.Builder` configuration to set the language.
Javohir Savriy's avatar
Javohir Savriy committed
235
236
237
238
239
240

## Custom Organization Details

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)).
Javohir Savriy's avatar
2.1.0    
Javohir Savriy committed
241
- *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 the imageView element, which has the *240x60* size.