ExampleWithOnActivityResultActivity.kt 2.22 KB
Newer Older
Javokhir Savriev's avatar
Javokhir Savriev committed
1
2
3
4
5
6
package uz.myid.sdk.sample

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import uz.myid.android.sdk.capture.*
Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
7
import uz.myid.android.sdk.capture.model.*
Javokhir Savriev's avatar
Javokhir Savriev committed
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
34
35
36
37
38
39
40
41
42
43
import java.util.*

class ExampleWithOnActivityResultActivity : 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)
    }

    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 sdkHash = "sdk_hash"
        val externalId = "external_id"
        val threshold = 0.50f

Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
44
        val organizationDetails = MyIdOrganizationDetails(
Javokhir Savriev's avatar
Javokhir Savriev committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
            phoneNumber = "1234567",
        )

        val myIdConfig = MyIdConfig.Builder(clientId)
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withSdkHash(sdkHash)
            .withExternalId(externalId)
            .withThreshold(threshold)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .withEntryType(MyIdEntryType.AUTH)
            .withResidency(MyIdResidentType.RESIDENT)
            .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)
    }
}