ExampleKotlinFragment.kt 1.73 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's avatar
Javokhir committed
7
import java.util.*
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
8
9
10

class ExampleKotlinFragment : Fragment(), MyIdResultListener {

Javokhir's avatar
Javokhir committed
11
    private val myIdClient = MyIdClient()
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

    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"
34
        val sdkHash = "sdk_hash"
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
35
        val externalId = "external_id"
Javohir Savriy's avatar
Javohir Savriy committed
36
37
38
39
40
        val threshold = 0.50f

        val organizationDetails = OrganizationDetails(
            phoneNumber = "1234567",
        )
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
41

Javokhir's avatar
Javokhir committed
42
        val myIdConfig = MyIdConfig.Builder(clientId)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
43
44
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
45
            .withSdkHash(sdkHash)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
46
            .withExternalId(externalId)
Javohir Savriy's avatar
Javohir Savriy committed
47
            .withThreshold(threshold)
Javokhir's avatar
Javokhir committed
48
            .withBuildMode(MyIdBuildMode.PRODUCTION)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
49
            .withEntryType(MyIdEntryType.AUTH)
Javokhir's avatar
Javokhir committed
50
51
            .withLocale(Locale("en"))
            .withCameraShape(MyIdCameraShape.CIRCLE)
Javohir Savriy's avatar
Javohir Savriy committed
52
            .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
53
54
55
            .withPhoto(false)
            .build()

Javokhir's avatar
Javokhir committed
56
        val intent = myIdClient.createIntent(requireActivity(), myIdConfig)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
57
58
59
60
61
        result.launch(intent)
    }

    private val result = takeUserResult(this)
}