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

import android.os.Bundle
import androidx.fragment.app.Fragment
import uz.myid.android.sdk.capture.*
Javohir Savriy's avatar
Javohir Savriy committed
6
import uz.myid.android.sdk.capture.model.OrganizationDetails
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

class ExampleKotlinFragment : Fragment(), MyIdResultListener {

    private val client: MyIdClient = MyIdClient()

    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"
        val passportData = "passport_data"
        val dateOfBirth = "date_of_birth"
        val externalId = "external_id"
Javohir Savriy's avatar
Javohir Savriy committed
34
35
36
37
38
39
        val threshold = 0.50f

        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
            logo = R.drawable.image_logo
        )
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
40
41
42
43
44

        val myIdConfig = MyIdConfig.builder(clientId)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withExternalId(externalId)
Javohir Savriy's avatar
Javohir Savriy committed
45
            .withThreshold(threshold)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
46
            .withEntryType(MyIdEntryType.AUTH)
Javohir Savriy's avatar
Javohir Savriy committed
47
            .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
48
49
50
51
52
53
54
55
56
57
58
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .withLocale(MyIdLocale.EN)
            .withPhoto(false)
            .build()

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

    private val result = takeUserResult(this)
}