ExampleJavaActivity.java 2.58 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.appcompat.app.AppCompatActivity;

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
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;
Javohir Savriy's avatar
Javohir Savriy committed
22
import uz.myid.android.sdk.capture.model.OrganizationDetails;
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
23
24
25

public class ExampleJavaActivity extends AppCompatActivity implements MyIdResultListener {

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

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

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

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

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

        MyIdConfig myIdConfig = new MyIdConfig.Builder(clientId)
                .withPassportData(passportData)
                .withBirthDate(dateOfBirth)
65
                .withSdkHash(sdkHash)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
66
                .withExternalId(externalId)
Javohir Savriy's avatar
Javohir Savriy committed
67
                .withThreshold(threshold)
Javokhir's avatar
Javokhir committed
68
                .withBuildMode(MyIdBuildMode.PRODUCTION)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
69
                .withEntryType(MyIdEntryType.AUTH)
Javokhir's avatar
Javokhir committed
70
71
                .withLocale(new Locale("en"))
                .withCameraShape(MyIdCameraShape.CIRCLE)
Javohir Savriy's avatar
Javohir Savriy committed
72
                .withOrganizationDetails(organizationDetails)
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
73
74
75
                .withPhoto(false)
                .build();

Javokhir's avatar
Javokhir committed
76
        Intent intent = myIdClient.createIntent(this, myIdConfig);
Javokhir Savriev's avatar
2.0.7  
Javokhir Savriev committed
77
78
79
80
81
        result.launch(intent);
    }

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