Skip to content

Commit e2473d3

Browse files
committed
Updated readme
1 parent 7a4d70c commit e2473d3

File tree

1 file changed

+75
-92
lines changed

1 file changed

+75
-92
lines changed

README.md

Lines changed: 75 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,15 @@ The Ver-ID Credentials SDK allows your app to capture an image of the user's ID
1717
1. Under `dependencies` add
1818
1919
```
20-
implementation 'com.appliedrec:id-capture:5.0.4'
20+
implementation 'com.appliedrec:id-capture:6.0.0'
2121
```
22-
1. Under `android/defaultConfig` add
23-
24-
```
25-
renderscriptTargetApi 18
26-
renderscriptSupportModeEnabled true
27-
```
2822
1. Open your app's **AndroidManifest.xml** file and add the following tag in `<application>` replacing `[your API secret]` with the API secret your received in step 1:
2923
3024
~~~xml
3125
<meta-data
3226
android:name="com.appliedrec.verid.apiSecret"
3327
android:value="[your API secret]" />
3428
~~~
35-
1. [Download resources archive](https://ver-id.s3.amazonaws.com/resources/models/v1/VerIDModels.zip) and put it in your app's **assets** folder.
36-
1. As an alternative to the previous step, specify a URL from which to download the resources. This will reduce the download size of your app. In the app's manifest file:
37-
38-
~~~xml
39-
<meta-data
40-
android:name="com.appliedrec.verid.resourcesURL"
41-
android:value="http://my.domain.com/path/to/resources.zip" />
42-
~~~
4329
4430
## Getting Started with the Ver-ID Credentials API
4531
To scan an ID card your app will start an activity with a Ver-ID ID Capture intent and receive the result in `onActivityResult`.
@@ -57,29 +43,26 @@ To scan an ID card your app will start an activity with a Ver-ID ID Capture inte
5743
public class MyActivity extends AppCompatActivity {
5844
5945
private static final int REQUEST_CODE_ID_CAPTURE = 0;
46+
private VerID verID;
6047
6148
@Override
6249
protected void onCreate(Bundle savedInstanceState) {
6350
super.onCreate(savedInstanceState);
6451
setContentView(R.layout.my_activity);
65-
VerID.shared.load(this, "myApiSecret", new VerID.LoadCallback() {
66-
@Override
67-
public void onLoad() {
52+
new VerIDFactory(this, new VerIDFactoryDelegate() {
53+
@Override
54+
public void veridFactoryDidCreateEnvironment(VerIDFactory verIDFactory, VerID verID) {
55+
MyActivity.this.verID = verID;
6856
// Ver-ID is now loaded. Here you may do things
6957
// like enable buttons that control the ID capture.
70-
}
71-
@Override
72-
public void onError(Exception exception) {
73-
// Ver-ID failed to load. Check your API secret.
74-
}
75-
});
76-
}
77-
78-
@Override
79-
protected void onDestroy() {
80-
super.onDestroy();
81-
// Unload Ver-ID when your activity gets destroyed
82-
VerID.shared.unload();
58+
}
59+
60+
@Override
61+
public void veridFactoryDidFailWithException(VerIDFactory verIDFactory, Exception e) {
62+
loadingIndicatorView.setVisibility(View.GONE);
63+
Toast.makeText(MainActivity.this, R.string.verid_failed_to_load, Toast.LENGTH_SHORT).show();
64+
}
65+
}).createVerID();
8366
}
8467
8568
/**
@@ -91,18 +74,16 @@ public class MyActivity extends AppCompatActivity {
9174
boolean showGuide = true;
9275
// If you want to show the result of the scan to the user set this to true
9376
boolean showResult = true;
94-
// To extract a face that's suitable for face recognition
95-
boolean detectFaceForRecognition = true;
9677
// Set the region where the requested card was issued.
9778
// If you want the API to guess use the RegionUtil utility class.
9879
// The utility class will base the region on the device's SIM card provider
9980
// or on the device's locale. If you want the user to choose the region
10081
// set the variable to Region.GENERAL.
101-
Region region = RegionUtil.getUserRegion(this);
82+
IDDocument document = RegionUtil.getDefaultDocumentForUserRegion(this);
10283
// Construct ID capture settings
103-
VerIDIDCaptureSettings settings = new VerIDIDCaptureSettings(region, showGuide, showResult, detectFaceForRecognition);
84+
VerIDIDCaptureSettings settings = new VerIDIDCaptureSettings(document, showGuide, showResult);
10485
// Construct an intent
105-
VerIDIDCaptureIntent intent = new VerIDIDCaptureIntent(this, settings);
86+
VerIDIDCaptureIntent intent = new VerIDIDCaptureIntent(this, verID, settings);
10687
// Start the ID capture activity
10788
startActivityForResult(intent, REQUEST_CODE_ID_CAPTURE);
10889
}
@@ -164,42 +145,37 @@ public class MyActivity extends AppCompatActivity {
164145
public class MyActivity extends AppCompatActivity {
165146
166147
private static final int REQUEST_CODE_LIVENESS_DETECTION = 1;
148+
private VerID verID;
167149
168150
@Override
169151
protected void onCreate(Bundle savedInstanceState) {
170152
super.onCreate(savedInstanceState);
171153
setContentView(R.layout.my_activity);
172-
VerID.shared.load(this, "myApiSecret", new VerID.LoadCallback() {
173-
@Override
174-
public void onLoad() {
154+
new VerIDFactory(this, new VerIDFactoryDelegate() {
155+
@Override
156+
public void veridFactoryDidCreateEnvironment(VerIDFactory verIDFactory, VerID verID) {
157+
MyActivity.this.verID = verID;
175158
// Ver-ID is now loaded. Here you may do things
176159
// like enable buttons that control the ID capture.
177-
}
178-
@Override
179-
public void onError(Exception exception) {
180-
// Ver-ID failed to load. Check your API secret.
181-
}
182-
});
183-
}
184-
185-
@Override
186-
protected void onDestroy() {
187-
super.onDestroy();
188-
// Unload Ver-ID when your activity gets destroyed
189-
VerID.shared.unload();
190-
}
160+
}
161+
162+
@Override
163+
public void veridFactoryDidFailWithException(VerIDFactory verIDFactory, Exception e) {
164+
loadingIndicatorView.setVisibility(View.GONE);
165+
Toast.makeText(MainActivity.this, R.string.verid_failed_to_load, Toast.LENGTH_SHORT).show();
166+
}
167+
}).createVerID();
168+
}
191169
192170
/**
193171
* Call this method to start the liveness detection session
194172
* (for example in response to a button click).
195173
*/
196174
void runLivenessDetection() {
197175
// Create liveness detection settings
198-
VerIDLivenessDetectionSessionSettings settings = new VerIDLivenessDetectionSessionSettings();
199-
// Ask Ver-ID to extract face templates needed for face recognition
200-
settings.includeFaceTemplatesInResult = true;
176+
LivenessDetectionSessionSettings settings = new LivenessDetectionSessionSettings();
201177
// Construct the liveness detection intent
202-
VerIDLivenessDetectionIntent intent = new VerIDLivenessDetectionIntent(this, settings);
178+
VerIDLivenessDetectionIntent intent = new VerIDLivenessDetectionIntent(this, verID, settings);
203179
// Start the liveness detection activity
204180
startActivityForResult(intent, REQUEST_CODE_LIVENESS_DETECTION);
205181
}
@@ -212,16 +188,16 @@ public class MyActivity extends AppCompatActivity {
212188
super.onActivityResult(requestCode, resultCode, data);
213189
if (requestCode == REQUEST_CODE_LIVENESS_DETECTION && resultCode == RESULT_OK && data != null) {
214190
// Extract the liveness detection session result from the data intent
215-
VerIDSessionResult verIDSessionResult = data.getParcelableExtra(VerIDActivity.EXTRA_SESSION_RESULT);
216-
if (verIDSessionResult == null || !verIDSessionResult.isPositive()) {
191+
VerIDSessionResult verIDSessionResult = data.getParcelableExtra(VerIDSessionActivity.EXTRA_RESULT);
192+
if (verIDSessionResult == null || verIDSessionResult.getError() != null) {
217193
return;
218194
}
219195
// Get the face and image URI of the first captured selfie
220-
HashMap<VerIDFace,Uri> faceImages = verIDSessionResult.getFaceImages(VerID.Bearing.STRAIGHT);
196+
HashMap<Face,Uri> faceImages = verIDSessionResult.getFaceImages(Bearing.STRAIGHT);
221197
if (faceImages.isEmpty()) {
222198
return;
223199
}
224-
Map.Entry<VerIDFace,Uri> faceImage = faceImages.entrySet().iterator().next();
200+
Map.Entry<Face,Uri> faceImage = faceImages.entrySet().iterator().next();
225201
// Get the bounds of the face detected in the first selfie
226202
Rect faceBounds = new Rect();
227203
faceImage.getKey().getBoundingBox().round(faceBounds);
@@ -264,51 +240,58 @@ public class CaptureResultActivity extends AppCompatActivity {
264240
// Obtain idCaptureResult and livenessDetectionResult, e.g. from intent parcelable
265241
// ...
266242
if (document == null || livenessDetectionResult == null) {
267-
updateScore(null);
268-
}
269-
270-
if (document.getFaceSuitableForRecognition() != null && livenessDetectionResult.getFacesSuitableForRecognition(VerID.Bearing.STRAIGHT).length > 0) {
271-
compareFaceTemplates();
243+
setAuthenticated(null);
244+
}
245+
if (document.getFaceSuitableForRecognition() != null && livenessDetectionResult.getFacesSuitableForRecognition(Bearing.STRAIGHT).length > 0) {
246+
new VerIDFactory(this, new VerIDFactoryDelegate() {
247+
@Override
248+
public void veridFactoryDidCreateEnvironment(VerIDFactory verIDFactory, VerID verID) {
249+
compareFaceTemplates(verID);
250+
}
251+
252+
@Override
253+
public void veridFactoryDidFailWithException(VerIDFactory verIDFactory, Exception e) {
254+
Toast.makeText(MainActivity.this, R.string.verid_failed_to_load, Toast.LENGTH_SHORT).show();
255+
}
256+
}).createVerID();
272257
return;
273258
}
274-
updateScore(null);
259+
setAuthenticated(null);
275260
}
276261
277-
private void compareFaceTemplates() {
262+
private void compareFaceTemplates(VerID verId) {
278263
AsyncTask.execute(new Runnable() {
279264
@Override
280265
public void run() {
281266
Float score = null;
282-
VerIDFace cardFace = document.getFaceSuitableForRecognition();
283-
VerIDFace[] liveFaces = livenessDetectionResult.getFacesSuitableForRecognition(VerID.Bearing.STRAIGHT);
284-
for (VerIDFace face : liveFaces) {
285-
try {
286-
float faceScore = FaceUtil.compareFaces(cardFace, face);
287-
if (score == null) {
288-
score = faceScore;
289-
} else {
290-
score = Math.max(faceScore, score);
291-
}
292-
} catch (Exception e) {
293-
e.printStackTrace();
294-
}
267+
RecognizableFace cardFace = document.getFaceSuitableForRecognition();
268+
RecognizableFace[] liveFaces = livenessDetectionResult.getFacesSuitableForRecognition(Bearing.STRAIGHT);
269+
try {
270+
float score = verID.getFaceRecognition().compareSubjectFacesToFaces(new RecognizableFace[]{cardFace}, liveFaces);
271+
float threshold = verID.getFaceRecognition().getAuthenticationThreshold();
272+
// If score >= threshold the user can be considered authenticated against the ID card
273+
final boolean authenticated =
274+
runOnUiThread(new Runnable() {
275+
@Override
276+
public void run() {
277+
updateScore(score);
278+
}
279+
});
280+
} catch (Exception e) {
281+
runOnUiThread(new Runnable() {
282+
@Override
283+
public void run() {
284+
setAuthenticated(null);
285+
}
286+
});
295287
}
296-
final Float finalScore = score;
297-
runOnUiThread(new Runnable() {
298-
@Override
299-
public void run() {
300-
updateScore(finalScore);
301-
}
302-
});
303288
}
304289
});
305290
}
306291
307292
@UiThread
308-
private void updateScore(Float score) {
309-
if (score != null) {
310-
// Display the score
311-
} else {
293+
private void setAuthenticated(Boolean authenticated) {
294+
if (authenticated == null) {
312295
// Display error
313296
}
314297
}

0 commit comments

Comments
 (0)