Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Huawei provides the secure fingerprint authentication capability. If the system is insecure, the callback method BioAuthnCallback.onAuthError() returns the error code BioAuthnPrompt.ERROR_SYS_INTEGRITY_FAILED. If the system is secure, fingerprint authentication is performed. For details about the fingerprint authentication error codes, please refer to the API Reference.
Only EMUI 4.0 and later versions support fingerprint authentication.
To use the fingerprint authentication capability, perform the following steps:
private BioAuthnPrompt createBioAuthnPrompt() {
// Callback.
BioAuthnCallback callback = new BioAuthnCallback() {
@Override
public void onAuthError(int errMsgId, CharSequence errString) {
showResult("Authentication error. errorCode=" + errMsgId + ",errorMessage=" + errString);
}
@Override
public void onAuthSucceeded(BioAuthnResult result) {
showResult("Authentication succeeded. CryptoObject=" + result.getCryptoObject());
}
@Override
public void onAuthFailed() {
showResult("Authentication failed.");
}
};
return new BioAuthnPrompt(this, ContextCompat.getMainExecutor(this), callback);
}private fun createBioAuthnPrompt(): BioAuthnPrompt {
// Callback.
val callback = object : BioAuthnCallback() {
override fun onAuthError(errMsgId: Int, errString: CharSequence) {
showResult("Authentication error. errorCode=$errMsgId,errorMessage=$errString")
}
override fun onAuthSucceeded(result: BioAuthnResult) {
if (result.cryptoObject != null) {
showResult("Authentication succeeded. CryptoObject=" + result.cryptoObject!!)
} else {
showResult("Authentication succeeded. CryptoObject=null")
}
}
override fun onAuthFailed() {
showResult("Authentication failed.")
}
}
return BioAuthnPrompt(this, ContextCompat.getMainExecutor(this), callback)
}// Build prompt information.
BioAuthnPrompt.PromptInfo.Builder builder =
new BioAuthnPrompt.PromptInfo.Builder().setTitle("This is the title.")
.setSubtitle("This is the subtitle")
.setDescription("This is the description");
// The user will first be prompted to authenticate with biometrics, but also given the option to
// authenticate with their device PIN, pattern, or password. setNegativeButtonText(CharSequence) should
// not be set if this is set to true.
builder.setDeviceCredentialAllowed(true);
// Set the text for the negative button. setDeviceCredentialAllowed(true) should not be set if this button text
// is set.
// builder.setNegativeButtonText("This is the 'Cancel' button.");
BioAuthnPrompt.PromptInfo info = builder.build();
resultTextView.setText("Start fingerprint authentication without CryptoObject.\nAuthenticating......\n");
bioAuthnPrompt.auth(info);// Build prompt information.
val builder = BioAuthnPrompt.PromptInfo.Builder().setTitle("This is the title.")
.setSubtitle("This is the subtitle")
.setDescription("This is the description")
// The user will first be prompted to authenticate with biometrics, but also given the option to
// authenticate with their device PIN, pattern, or password. setNegativeButtonText(CharSequence) should
// not be set if this is set to true.
builder.setDeviceCredentialAllowed(true)
// Set the text for the negative button. setDeviceCredentialAllowed(true) should not be set if this button text
// is set.
// builder.setNegativeButtonText("This is the 'Cancel' button.");
val info = builder.build()
resultTextView!!.text = "Start fingerprint authentication without CryptoObject.\nAuthenticating......\n"
bioAuthnPrompt!!.auth(info)Huawei provides the secure facial authentication capability. If the system is insecure, the callback method BioAuthnCallback.onAuthError returns the error code FaceManager.FACE_ERROR_SYS_INTEGRITY_FAILED. If the system is secure, facial authentication is performed. For details about the facial authentication error codes, please refer to the API Reference.
To use the facial authentication capability, perform the following steps:
// Callback.
BioAuthnCallback callback = new BioAuthnCallback() {
@Override
public void onAuthError(int errMsgId, CharSequence errString) {
showResult("Authentication error. errorCode=" + errMsgId + ",errorMessage=" + errString
+ (errMsgId == 1012 ? " The camera permission may not be enabled." : ""));
}
@Override
public void onAuthHelp(int helpMsgId, CharSequence helpString) {
resultTextView
.append("Authentication help. helpMsgId=" + helpMsgId + ",helpString=" + helpString + "\n");
}
@Override
public void onAuthSucceeded(BioAuthnResult result) {
showResult("Authentication succeeded. CryptoObject=" + result.getCryptoObject());
}
@Override
public void onAuthFailed() {
showResult("Authentication failed.");
}
};// Callback.
val callback = object : BioAuthnCallback() {
override fun onAuthError(errMsgId: Int, errString: CharSequence) {
showResult("Authentication error. errorCode=" + errMsgId + ",errorMessage=" + errString
+ if (errMsgId == 1012) " The camera permission may not be enabled." else "")
}
override fun onAuthHelp(helpMsgId: Int, helpString: CharSequence) {
resultTextView!!
.append("Authentication help. helpMsgId=$helpMsgId,helpString=$helpString\n")
}
override fun onAuthSucceeded(result: BioAuthnResult) {
showResult("Authentication succeeded.")
}
override fun onAuthFailed() {
showResult("Authentication failed.")
}
}// Cancellation signal. CancellationSignal cancellationSignal = new CancellationSignal(); FaceManager faceManager = new FaceManager(this); // Flags. int flags = 0; // Authentication message handler. Handler handler = null; // You are advised to set CryptoObject to null. KeyStore is not associated with face authentication in the current // version. KeyGenParameterSpec.Builder.setUserAuthenticationRequired() must be set to false in this scenario. CryptoObject crypto = null; faceManager.auth(crypto, cancellationSignal, flags, callback, handler);
// Cancellation signal. val cancellationSignal = CancellationSignal() val faceManager = FaceManager(this) // Flags. val flags = 0 // Authentication message handler. val handler: Handler? = null // You are advised to set CryptoObject to null. KeyStore is not associated with face authentication in the current // version. KeyGenParameterSpec.Builder.setUserAuthenticationRequired() must be set to false in this scenario. val crypto: CryptoObject? = null faceManager.auth(crypto, cancellationSignal, flags, callback, handler)
For details about the complete sample code, please refer to BioAuthn-AndroidX.