ExampleJavaActivity.java 2.51 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
53
    }

    @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
54
55
56
57
58
59
        float threshold = 0.5f;

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

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

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

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