2 User Guide
2.1 Sample project
A sample project for testing is provided under Android Studio. Please refer to the following steps to import.
Click File > New > Import Project and select Sample to import into Android Studio
Enter the account information:
API_KEY
andAPI_SECRET
Before using the SDK, you need to configure your API_KEY
and API_SECRET
. Please refer to the code in SilentLivenessActivity
:
Rename the license file and place it in the specified directory (please refer to License introduction)
2.2 Integration in Android Studio
2.2.1 Method 1: Quick integration with module dependency
From
File > New > Import Module ...
select../Sample/common-silent
. Import common-silent into the project as an import module and add dependencies to build.gradle in app project:
Ensure that the model file (.model) and the license file (.lic) in the assets directory in common-silent are loaded successfully.
Create
repositories
under project (same level as your app project) and copyliveness-silent-online-cn-release.aar
to this directory. Changebuild.gradle
in the root directory, and then add configuration torepositories
as follows:
Add permission statement in AndroidManifest.xml as the following example:
Add Activity statement in the AndroidManifest.xml file as the following example:
Static liveness detection can be used by calling SilentLivenessActivity. For details, please refer to
startDetectionActivity()
method ofStartPageFragment
in Sample.
2.2.2 Method 2: Deep integration using the libs method; customized development using SDK instead of common-silent
Create a new libs
folder under the corresponding app module (not required if libs folder already exists) and copy liveness-silent-online-cn-release.aar
to libs
. Add the following configuration to build.gradle
which is under the app module:
Then, the SDK can be called directly for development.
2.3 Resolve code obfuscation
Since crashes may occur after code obfuscation, it is recommended to solve the code obfuscation issue first by the obfuscation configuration.
Specifically, the following code is added to the proguard file to resolve this issue:
2.4 Interface call flow
2.4.1 Initialization
The license file and model file needs to be copied to the device in advance.
Call FileUtil.copyAssetsToFile or use other methods to refer to Sample. Then call the init method in SilentLivenessApi.
When the minimum detection duration and the minimum number of detection frames that can pass the silent liveness detection need to be set, they can be set by calling the setPassCondition
method after adjusting the init
method. For the method description, refer to 2 Optional condition settings for silent liveness detection.
For more information, please refer to OnLivenessListener liveness detection status listener.
Set quality detection
2.4.2 Optional condition setting for silent liveness detection
Call the following method in SilentLivenessApi to set.
Set the conditions for liveness detection pass:
setPassCondition(final int minDuration, final int minFrames)
Set the timeout time, in seconds. The default timeout time is 10s:
setDetectTimeout(int timeout)
Set the judgment condition for the face distance. When the parameter value is not in the range or closeRate is not 0 and farRate is greater than closeRate, STID_E_FARCLOSE_INVALID error is reported:
setFaceDistanceRate(float farRate, float closeRate)
Set whether eyebrow occlusion function is needed. The default value is false:
setBrowOcclusionEnable(final boolean enable)
Set whether occlusion function is needed. The default value is false:
setOcclusionEnable(final boolean enable)
Set the threshold of liveness detection:
setThreshold(final float threshold)
Set the threshold of eye status:
setEyeOpenThreshold(final float threshold)
Set whether blurriness detection is needed and the threshold of it:
setBlurryFilterEnable(final boolean enable, final float threshold)
Set whether brightness detection is needed and the threshold of it:
setIlluminationFilterEnable(final boolean enable, final float lowLightThreshold, final float brightThreshold)
2.4.3 Ready to start testing
Prepare to start the test by calling SilentLivenessApi start()
method.
Method description: Prepare to start testing.
2.4.4 Input data and start detection
Call SilentLivenessApi inputData method to input image data and other parameters for detection.
Method description: Input for image detection.
2.4.5 Get test results
Implement the method in OnLivenessListener to get the detection result.
Method description: Complete initialization.
Method description: Update alignment status.
Method description: Failed Fiveness detection.
Successful liveness detection
For more information, please refer to OnLivenessListener liveness detection status listener.
2.4.6 Stop the current detection and reset the detection status
Call the SilentLivenessApi stop
method.
Method description: Stop the current detection, and reset the detection status. This method is used to retry after failure. It should be called after the init
successes and before the release
is called. After it is called, start
can be used to restart detection.silentlivenessapi.md)
2.4.7 Cancel detection and release resources
Call the SilentLivenessApi release
method.
Method description: Cancel detection and release resources.
2.5 Call private cloud interface for face comparison
After successful liveness detection, the SDK will return the corresponding face image and an encrypted binary file. The returned value can be used as a parameter of the public cloud interface for face comparison.
For the specific description of the private cloud interface, please refer to the SenseID private cloud API manual.
Last updated