Documentation

Integration Documentation(Source Code)

Installation

  1. Add the repository
    maven { url 'https://public-n3.advai.net/repository/maven-releases/' }
  2. Click to download the UI source code.
  3. Module Integration: Extract the downloaded zip file to obtain the SDK module. Import this module into your project and use it as a standard project module.
  4. If your application has package size constraints or you need to reduce the app bundle size, you can optimize by excluding the model file module from the dependencies in step 2. This modification reduces the SDK package size by approximately 1.4MB. The model files will be downloaded automatically when users first launch the SDK. Please be aware that network connectivity issues may cause download failures.
    implementation ('ai.advance.mobile-sdk.android:liveness-detection:4.0.0'){
    		exclude group: 'ai.advance.mobile-sdk.android', module: 'liveness-detection-model'
    }

Migration Guides

If you are upgrading from an older version of the Liveness SDK, please refer to this document to understand the changes.

Usage

  1. Initialization SDK.

    The init method need to be called in your application class

    // If you have subscribed to the Global liveness service, then you need to set the last boolean value to true, otherwise please set it to false.
    GuardianLivenessDetectionSDK.init(this,your market,false);
  2. Check license

    The license is obtained by your server calling our openAPI, you need to check license before starting the liveness detection activity.

    String license = "xxx";
    String checkResult = GuardianLivenessDetectionSDK.setLicenseAndCheck(license);
    if ("SUCCESS".equals(checkResult)) {
        // license valid
       startLivenessActivity();
    } else {
      // license is not available, expired/wrong format/appId not filed
    }
    
    The returned values of checkResult:
    
    APPLICATION_ID_NOT_MATCH: The package name is not within the authorized scope, please check your package name.
    
    LICENSE_EXPIRE: The license has expired, please confirm that the user has calibrated the phone time.
    
    ERROR_LICENSE(1): The license parsing succeeded, but necessary authentication information is missing, this case generally will not occur.
    
    ERROR_LICENSE(2): The license parsing succeeded, but the internal format is incorrect, this case also generally will not occur.
    
    ERROR_LICENSE(3): It is highly likely that an incompatible SDK license is being used, such as using an IQA license for liveness detection.
    
    ERROR_LICENSE(4, 5): Parsing failed, please check if the license has issues like mismatched quotes, line breaks, etc.
  3. You can create SDK launch parameters using the method below.
    For valid values of livenessType, pleaserefer to this link.

    LivenessConfig configs = new LivenessConfig.Builder()
                    .setCameraType(CameraType.FRONT)// FRONT or BACK camera
                    .setQueryId(queryId)// In ticket authentication mode, you need to pass the queryId,other authentication modes do not require it.
                    .setTicket(ticket)// In ticket authentication mode, you need to pass the ticket,other authentication modes do not require it.
                    .setDetectOcclusion(false)// Set whether to enable occlusion detection. It is false by default.
                    .setAuditImageConfig(new AuditImageConfig // Audit image configs
                            .AuditImageConfigBuilder()
                            .setEnableCollectSwitch(true) // Set whether to enable audit image collection. It is false by default.
                            .setImageWidth(400)// The width of audit images
                            .setImageQuality(30)// The quality of audit images,must in [30,100].It is 30 by default.
                            .setRelativeSecondsCaptureAfterCameraLaunched(3f)// If you want to collect images relative to the camera's open time, you can set the relative time here (unit: seconds).
                            .build())
                    .setLivenessType("your liveness type")// Set the liveness type
                    .setSignatureId("your signature id")// Set the signatureId
                    .setMaskColor(Color.GREEN))// Set the LivenessView mask color
                    .setOvalColor(Color.GREEN)// Set the oval light color
                    .setOvalNormalColor(Color.GRAY)// Set the oval normal color
                    .setDistantNearTimeout(50_000) // Set the timeout limit of Distant-Near liveness stage
                    .setSilentTimeout(50_000)// Set the timeout limit of Silent liveness stage
                    .setActionTimeout(10_000)// Set the timeout limit for each action.
                    .setPrepareMillSeconds(0)// Set the waiting time before starting liveness detection (during this stage, the client can perform UI interactions to prompt the user to get ready).
                    .setResultPictureSize(600)// Customize the size of the returned image,Settable input range: [300,1000], unit: pixels.It is 600 by default.
                    .setMaxRecordVideoSeconds(600)// Set the maximum duration for video recording in seconds,unit:seconds,If set to 0, it means no video will be recorded.
                    .setUserId("your unique user id")// You can use this method to pass your user unique identifier to us, we will establish a mapping relationship based on the identifier.It is helpful for us to check the log when encountering problems.
                    .build();
  4. Start liveness detection

    public class SomeActivity extends Activity{
    
        /**
         * requestCode
         */
        public static final int REQUEST_CODE_LIVENESS = xxxx;
    
        /**
         * start Liveness Activity
         */
        private void startLivenessActivity() {
          Intent intent = new Intent(this, LivenessActivity.class);
    			intent.putExtra(LivenessActivity.EXTRA_CONFIGS, configs);
          startActivityForResult(intent, REQUEST_CODE_LIVENESS);
      }
    
      /**
       * get Liveness result
       */
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == REQUEST_CODE_LIVENESS) {
            // Please make sure to save eventId for contacting us for troubleshooting purposes
            String eventId = LivenessResult.getEventId();
            File videoFile = LivenessResult.getVideoFile(this);// The video file
            if (LivenessResult.isSuccess()) {// Success
              String livenessId = LivenessResult.getLivenessId();// livenessId
              boolean pay = LivenessResult.isPay();// pay status
              Bitmap livenessBitmap = LivenessResult.getLivenessBitmap();// picture(Far)
              Bitmap nearBitmap = LivenessResult.getNearBitmap();// picture(Near)
              List<LivenessImageData> auditImageList = LivenessResult.getAuditImageList();// Audit images
            } else {// Failure
              String errorCode = LivenessResult.getErrorCode();// error code
              String errorMsg = LivenessResult.getErrorMsg();// error message
                ...
            }
          }
        }
      }
    

Error Code

See Error Code

FAQ

See FAQ