Physical ID Card Capture

The physical ID Capture introduces a way to capture photos of physical ID documents

Steps to implementation

Step 1

In your layout file add the SmartCardView. We advise on giving the view as much real estate as possible so match parent on both height and width is advisable

<com.smileidentity.libsmileid.core.idcapture.SmartCardView
        android:id="@+id/id_capture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        <!--optional fields for customisation-->
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:faceDetectedMessage="Custom face detected message"
        app:blurryMessage="Custom message for when capture is blurry"
        app:insufficientLightMessage="Custom message for when there is insufficient light"
        app:fitIdMessage="Custom message informing the user to fit the id on the rectangle and tap for focus"
        app:flashMissingErrorMessage="Custom flash missing error message"
        app:loadingMessage="Custom message for when ID capture is loading"
        app:detectingFaceMessage="Custom message for when ID capture face detection is in progress"
        app:noFaceDetectedMessage="Custom no face detected message"
        app:capturedBlurryMessage="Custom blurriness detected in captured image"
        app:capturedDarkMessage="Custom darkness detected in captured image"
        >
 </com.smileidentity.libsmileid.core.idcapture.SmartCardView>

Step 2

Initialize the view in your view controller as normal and set the listener so that the SDK can pass back information on the capture

SmartCardView smartCardView = findViewById(R.id.id_capture);
smartCardView.setListener(this);

Step 3

Set your desired id type, this is an instance of IDType enum with options

  • Idcard => Aspect ratio 1.4 or normal credit card sized IDs

  • Passport => Aspect ratio 1.6 or normal passbort booklet sized IDs

  • Other => will default to 1.4 aspect ratio

smartCardView.setIdType(<IdType>);

Step 4

Start Capture, typically this should be called in your onResume so that the view maintains state with the implementing Activity/Fragment

@Override
protected void onResume() {
    super.onResume();
    try {
        mSmartCardView.startCapture(mCurrentTag);
    } catch (SIDException e) {
        e.printStackTrace();
    }
}

The start capture method will display the view which should look like below

The method has a couple of possible errors that should be catered for this is important to make sure users get the best user experience and for handling possible failures gracefully.

  • //When camera initialisation fails
    SIDError.COULD_NOT_INITIALIZE_CAMERA
    
    //when no listener is set
    SIDError.MISSING_LISTENER
    
    //When an empty or invalid tag is set
    SIDError.INVALID_TAG_FORMAT
    
    //If your app does not have camera permissions
    SIDError.PERMISSION_ERROR
    
    //If the camera fails to process the captured image
    SIDError.ID_CARD_PICTURE_CALLBACK_FAILED

Step 5

Implement pausing on the capture to handle view lifecycles

@Override
protected void onPause() {
    super.onPause();
    mSmartCardView.pauseCapture();
}

Step 6

Error handling and callbacks from the ID Capture

 @Override
public void onSmartCardViewError(Exception error) {
    //todo:handle this
}

@Override
public void onSmartCardViewComplete(Bitmap idCardBitmap, boolean faceFound) {
    //idCardBitmap the captured id card image
    //faceFound true if a face was found  on the ID
}

@Override
public void onSmartCardViewClosed() {
  //User pressed X and the ID Card has been closed
}

ID Capture Custom Messaging

To enable customization and internationalization from version 7.1.0 the ID Capture allows messaging customization through out the whole capture process as demonstrated in step 1

Last updated