Running your First Job

On to the good stuff

To configure a your job in preparation to sending it to Smile ID you will need to start up the SmartSelfie camera using SmartSelfieManager then set up you job request by building out an SIDConfig object to send to Smile Identity via a SIDNetworkRequest.

Using the SIDConfig Builder() You will be able to set the details of that specific job in order to achieve the required goal when sending it to Smile ID.

A SelfieCaptureConfig contains the camera settings of the SmartSelfie camera

Activity
Layout
Activity
package com.demo.smileid.sid_sdk;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.smileidentity.libsmileid.core.CameraSourcePreview;
import com.smileidentity.libsmileid.core.RetryOnFailurePolicy;
import com.smileidentity.libsmileid.core.SIDConfig;
import com.smileidentity.libsmileid.core.SIDNetworkRequest;
import com.smileidentity.libsmileid.core.SIDResponse;
import com.smileidentity.libsmileid.core.SelfieCaptureConfig;
import com.smileidentity.libsmileid.core.SmartSelfieManager;
import com.smileidentity.libsmileid.exception.SIDException;
import com.smileidentity.libsmileid.model.SIDNetData;
import java.util.concurrent.TimeUnit;
public class MainActivity extends AppCompatActivity implements
SmartSelfieManager.OnCompleteListener, SIDNetworkRequest.OnCompleteListener,
SIDNetworkRequest.OnErrorListener,
SIDNetworkRequest.OnUpdateListener,
SIDNetworkRequest.OnEnrolledListener {
private static final int PERMISSION_ALL = 1;
private String[] PERMISSIONS = {Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
private SmartSelfieManager smartSelfieManager;
SIDConfig mConfig;
CameraSourcePreview mPreview;
SIDNetworkRequest mSINetworkrequest;
String mTag;
String AUTH_URL;
String PARTNER_URL;
String PARTNER_PORT;
String LAMBDA_URL;
String SID_PORT;
private TextView mPrompt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_main);
requestPermissions();
mPreview = findViewById(R.id.previewCamera);
mPrompt = findViewById(R.id.prompt_tv);
mTag = "Noosrat";
AUTH_URL = "api/v2/#/auth_smile/";
PARTNER_URL = "https://test-smileid.herokuapp.com/";
PARTNER_PORT = "8080";
LAMBDA_URL = "https://3eydmgh10d.execute-api.us-west-2.amazonaws.com/test/";
SID_PORT = "8443";
smartSelfieManager = new SmartSelfieManager(getCaptureConfig());
mSINetworkrequest = new SIDNetworkRequest(this);
smartSelfieManager.setOnCompleteListener(this);
mSINetworkrequest.setOnCompleteListener(this);
mSINetworkrequest.set0nErrorListener(this);
mSINetworkrequest.setOnUpdateListener(this);
mSINetworkrequest.setOnEnrolledListener(this);
if (permissionGranted(PERMISSIONS)) {
smartSelfieManager.captureSelfie(mTag);
} else {
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
}
private void requestPermissions() {
}
private boolean permissionGranted(String... permissions) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
@Override
public void onComplete(Bitmap fullPreviewFrame) {
if (fullPreviewFrame != null) {
//Process returned full preview frame
}
smartSelfieManager.stop();
SIDNetData data = new SIDNetData();
data.setAuthUrl(AUTH_URL);
data.setPartnerUrl(PARTNER_URL);
data.setPartnerPort(PARTNER_PORT);
data.setLambdaUrl(LAMBDA_URL);
data.setSidPort(SID_PORT);
SIDConfig.Builder builder = new SIDConfig.Builder(this)
.setRetryOnfailurePolicy(getRetryOnFailurePolicy())
.setMode(SIDConfig.Mode.ENROLL)
.setSmileIdNetData(data)
.setJobType(4)
.useIdCard(false);
mConfig = builder.build(mTag);
mSINetworkrequest.submit(mConfig);
mPrompt.setText("Job has been submitted");
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
private SelfieCaptureConfig getCaptureConfig() {
return new SelfieCaptureConfig.Builder(this)
.setCameraType(SelfieCaptureConfig.FRONT_CAMERA)
.setPreview(mPreview)
.setManualSelfieCapture(false)
.setFlashScreenOnShutter(true)
.build();
}
private RetryOnFailurePolicy getRetryOnFailurePolicy() {
RetryOnFailurePolicy retryOnFailurePolicy = new RetryOnFailurePolicy();
retryOnFailurePolicy.setRetryCount(10);
retryOnFailurePolicy.setRetryTimeout(TimeUnit.SECONDS.toMillis(15));
return retryOnFailurePolicy;
}
@Override
public void onComplete() {
Toast.makeText(this, "Job Complete", Toast.LENGTH_SHORT).show();
mPrompt.setText("Job Complete");
}
@Override
public void onEnrolled(SIDResponse sidResponse) {
}
@Override
public void onError(SIDException e) {
}
@Override
public void onUpdate(int i) {
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.demo.smileid.sid_sdk.MainActivity">
<com.smileidentity.libsmileid.core.CameraSourcePreview
android:id="@+id/previewCamera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingBottom="80dp"
app:captured_progress_state_color="@color/arc_color_trans_60per"
app:capturing_progress_state_color="@color/arc_color_trans_80per"
app:overlay_height="300dp"
app:overlay_width="250dp"
app:progress_width="15dp" />
<TextView
android:id="@+id/prompt_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="34dp"
android:gravity="center"
android:text="Put your face inside the oval"
android:textColor="@android:color/black"
android:textSize="20sp" />
</RelativeLayout>