ExampleKotlinFragment.kt 1.54 KB
Newer Older
Javokhir Savriev's avatar
Javokhir Savriev committed
1
2
3
4
package uz.myid.sdk.sample

import android.os.Bundle
import androidx.fragment.app.Fragment
Javokhir's avatar
2.2.7    
Javokhir committed
5
6
7
8
9
10
11
import uz.myid.android.sdk.capture.MyIdClient
import uz.myid.android.sdk.capture.MyIdConfig
import uz.myid.android.sdk.capture.MyIdException
import uz.myid.android.sdk.capture.MyIdResult
import uz.myid.android.sdk.capture.MyIdResultListener
import uz.myid.android.sdk.capture.model.MyIdBuildMode
import uz.myid.android.sdk.capture.takeUserResult
Javokhir Savriev's avatar
Javokhir Savriev committed
12
13
14

class ExampleKotlinFragment : Fragment(), MyIdResultListener {

Javokhir's avatar
2.2.7    
Javokhir committed
15
    private val client = MyIdClient()
Javokhir Savriev's avatar
Javokhir Savriev committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

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

    override fun onSuccess(result: MyIdResult) {
        // Get face bitmap and result code
    }

    override fun onError(e: MyIdException) {
        // Get error message and code
    }

    override fun onUserExited() {
        // User exited sdk
    }

    private fun startMyId() {
        val clientId = "client_id"
Javokhir's avatar
2.2.7    
Javokhir committed
36
37
        val clientHash = "client_hash"
        val clientHashId = "client_hash_id"
Javokhir Savriev's avatar
Javokhir Savriev committed
38
39
40
        val passportData = "passport_data"
        val dateOfBirth = "date_of_birth"

Javokhir's avatar
2.2.7    
Javokhir committed
41
42
        val config = MyIdConfig.Builder(clientId)
            .withClientHash(clientHash, clientHashId)
Javokhir Savriev's avatar
Javokhir Savriev committed
43
44
45
46
47
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .build()

Javokhir's avatar
2.2.7    
Javokhir committed
48
        val intent = client.createIntent(requireActivity(), config)
Javokhir Savriev's avatar
Javokhir Savriev committed
49
50
51
52
53
        result.launch(intent)
    }

    private val result = takeUserResult(this)
}