ExampleJavaFragment.java 2.31 KB
Newer Older
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
1
2
3
4
5
6
7
8
9
10
11
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;

Javokhir's avatar
Javokhir committed
12
13
import java.util.Locale;

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
14
import uz.myid.android.sdk.capture.MyIdBuildMode;
Javokhir's avatar
Javokhir committed
15
import uz.myid.android.sdk.capture.MyIdCameraShape;
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
16
17
18
19
20
21
22
23
24
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.MyIdResult;
import uz.myid.android.sdk.capture.MyIdResultListener;

public class ExampleJavaFragment extends Fragment implements MyIdResultListener {

Javokhir's avatar
Javokhir committed
25
    private final MyIdClient myIdClient = new MyIdClient();
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
26
27
28
29
30
31
32
33
34

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

    @Override
    public void onSuccess(@NonNull MyIdResult result) {
Javokhir's avatar
Javokhir committed
35
        // Get face bitmap, result code, comparison value
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    }

    @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";
52
        String sdkHash = "sdk_hash";
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
53
        String externalId = "external_id";
Javohir Savriy's avatar
Javohir Savriy committed
54
55
        float threshold = 0.5f;

Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
56
57
58
        MyIdConfig myIdConfig = new MyIdConfig.Builder(clientId)
                .withPassportData(passportData)
                .withBirthDate(dateOfBirth)
59
                .withSdkHash(sdkHash)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
60
                .withExternalId(externalId)
Javohir Savriy's avatar
Javohir Savriy committed
61
                .withThreshold(threshold)
Javokhir's avatar
Javokhir committed
62
                .withBuildMode(MyIdBuildMode.PRODUCTION)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
63
                .withEntryType(MyIdEntryType.AUTH)
Javokhir's avatar
Javokhir committed
64
65
                .withLocale(new Locale("en"))
                .withCameraShape(MyIdCameraShape.CIRCLE)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
66
67
68
                .withPhoto(false)
                .build();

Javokhir's avatar
Javokhir committed
69
        Intent intent = myIdClient.createIntent(requireActivity(), myIdConfig);
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
70
71
72
73
74
        result.launch(intent);
    }

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