ExampleJavaFragment.java 2.21 KB
Newer Older
Javokhir Savriev's avatar
Javokhir Savriev committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 java.util.Locale;

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;
Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
19
20
21
import uz.myid.android.sdk.capture.model.MyIdBuildMode;
import uz.myid.android.sdk.capture.model.MyIdCameraShape;
import uz.myid.android.sdk.capture.model.MyIdEntryType;
Javokhir Savriev's avatar
Javokhir Savriev committed
22
import uz.myid.android.sdk.capture.model.MyIdImageFormat;
Javohir Savriy's avatar
2.1.6    
Javohir Savriy committed
23
import uz.myid.android.sdk.capture.model.MyIdResidentType;
Javokhir Savriev's avatar
Javokhir Savriev committed
24
import uz.myid.android.sdk.capture.model.MyIdResolution;
Javokhir Savriev's avatar
Javokhir Savriev committed
25
26
27

public class ExampleJavaFragment extends Fragment implements MyIdResultListener {

Javokhir's avatar
2.2.7    
Javokhir committed
28
    private final MyIdClient client = new MyIdClient();
Javokhir Savriev's avatar
Javokhir Savriev committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

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

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

    @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";
Javokhir's avatar
2.2.7    
Javokhir committed
53
54
        String clientHash = "client_hash";
        String clientHashId = "client_hash_id";
Javokhir Savriev's avatar
Javokhir Savriev committed
55
56
57
        String passportData = "passport_data";
        String dateOfBirth = "date_of_birth";

Javokhir's avatar
2.2.7    
Javokhir committed
58
59
        MyIdConfig config = new MyIdConfig.Builder(clientId)
                .withClientHash(clientHash, clientHashId)
Javokhir Savriev's avatar
Javokhir Savriev committed
60
61
62
63
64
                .withPassportData(passportData)
                .withBirthDate(dateOfBirth)
                .withBuildMode(MyIdBuildMode.PRODUCTION)
                .build();

Javokhir's avatar
2.2.7    
Javokhir committed
65
        Intent intent = client.createIntent(requireActivity(), config);
Javokhir Savriev's avatar
Javokhir Savriev committed
66
67
68
69
70
        result.launch(intent);
    }

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