ExampleJavaFragment.java 2.39 KB
Newer Older
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package uz.myid.sdk.sample;

import static uz.myid.android.sdk.capture.MyIdResultKt.takeUserResult;

import android.content.Intent;
import android.os.Bundle;

import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import uz.myid.android.sdk.capture.MyIdBuildMode;
import uz.myid.android.sdk.capture.MyIdClient;
import uz.myid.android.sdk.capture.MyIdConfig;
import uz.myid.android.sdk.capture.MyIdEntryType;
import uz.myid.android.sdk.capture.MyIdException;
import uz.myid.android.sdk.capture.MyIdLocale;
import uz.myid.android.sdk.capture.MyIdResult;
import uz.myid.android.sdk.capture.MyIdResultListener;
Javohir Savriy's avatar
Javohir Savriy committed
20
import uz.myid.android.sdk.capture.model.OrganizationDetails;
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

public class ExampleJavaFragment extends Fragment implements MyIdResultListener {

    private final MyIdClient client = new MyIdClient();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startMyId();
    }

    @Override
    public void onSuccess(@NonNull MyIdResult result) {
        // Get face bitmap and result code
    }

    @Override
    public void onError(@NonNull MyIdException e) {
        // Get error message and code
    }

    @Override
    public void onUserExited() {
        // User exited sdk
    }

    private void startMyId() {
        String clientId = "client_id";
        String passportData = "passport_data";
        String dateOfBirth = "date_of_birth";
        String externalId = "external_id";
Javohir Savriy's avatar
Javohir Savriy committed
52
53
54
55
56
57
        float threshold = 0.5f;

        OrganizationDetails organizationDetails = new OrganizationDetails(
                "1234567",
                R.drawable.image_logo
        );
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
58
59
60
61
62

        MyIdConfig myIdConfig = new MyIdConfig.Builder(clientId)
                .withPassportData(passportData)
                .withBirthDate(dateOfBirth)
                .withExternalId(externalId)
Javohir Savriy's avatar
Javohir Savriy committed
63
                .withThreshold(threshold)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
64
                .withEntryType(MyIdEntryType.AUTH)
Javohir Savriy's avatar
Javohir Savriy committed
65
                .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
66
67
68
69
70
71
72
73
74
75
76
                .withBuildMode(MyIdBuildMode.PRODUCTION)
                .withLocale(MyIdLocale.EN)
                .withPhoto(false)
                .build();

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

    private final ActivityResultLauncher<Intent> result = takeUserResult(this, this);
}