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

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
Javokhir's avatar
2.2.7    
Javokhir committed
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
Javokhir Savriev's avatar
Javokhir Savriev committed
12
13
14

class ExampleWithOnActivityResultActivity : AppCompatActivity(), 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

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

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
Javokhir's avatar
2.2.7    
Javokhir committed
24
        client.handleActivityResult(resultCode, this)
Javokhir Savriev's avatar
Javokhir Savriev committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    }

    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
41
42
        val clientHash = "client_hash"
        val clientHashId = "client_hash_id"
Javokhir Savriev's avatar
Javokhir Savriev committed
43
44
45
        val passportData = "passport_data"
        val dateOfBirth = "date_of_birth"

Javokhir's avatar
2.2.7    
Javokhir committed
46
47
        val config = MyIdConfig.Builder(clientId)
            .withClientHash(clientHash, clientHashId)
Javokhir Savriev's avatar
Javokhir Savriev committed
48
49
50
51
52
53
54
55
56
57
            .withPassportData(passportData)
            .withBirthDate(dateOfBirth)
            .withBuildMode(MyIdBuildMode.PRODUCTION)
            .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.
        */
Javokhir's avatar
2.2.7    
Javokhir committed
58
        client.startActivityForResult(this, 1, config)
Javokhir Savriev's avatar
Javokhir Savriev committed
59
60
    }
}