我正在我的应用程序中实现android本机指纹API。 根据文档,FINGERPRINT_ERROR_TIMEOUT(3)是在超时的情况下应该接收的错误代码。还提到的是:
int FINGERPRINT_ERROR_TIMEOUT
Error state returned when the current request has been running too long.
This is intended to prevent programs from waiting for the fingerprint sensor indefinitely.
The timeout is platform and sensor-specific, but is generally on the order of 30 seconds.
在我的情况下,这个超时回调没有发生。我目前正在使用三星S7来测试它。任何人都可以帮助我们如何配置此值以及确定默认情况下未发生超时的原因。
EDIT1:
添加指纹处理程序的代码:
@RequiresApi(api = Build.VERSION_CODES.M)
public class FingerprintHandler extends
FingerprintManager.AuthenticationCallback {
private CancellationSignal cancellationSignal;
private Context appContext;
private boolean sendCancellation=false;
public FingerprintHandler(Context context) {
appContext = context;
}
public void startAuth(FingerprintManager manager,
FingerprintManager.CryptoObject cryptoObject) {
cancellationSignal = new CancellationSignal();
if (ActivityCompat.checkSelfPermission(appContext,
Manifest.permission.USE_FINGERPRINT) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
@Override
public void onAuthenticationError(int errMsgId,
CharSequence errString) {
Log.d(TAG,"Authentication error callback");
Log.d(TAG,"Error Value: "+errMsgId);
switch(errMsgId){
case FINGERPRINT_ERROR_LOCKOUT:
Log.d(TAG,"Fingerprint error lockout");
nativeLocked = true;
mPreferences.edit().putLong(LAST_FAILURE, System.currentTimeMillis()).apply();
mPreferences.edit().putBoolean("nativeLocked", true).apply();
showError(getString(R.string.test_bio_fingerprint_fingerprint_authentication_failed));
mCancelButton.setEnabled(true);
dialogHandler.postDelayed(new Runnable() {
@Override
public void run() {
mCancelButton.setEnabled(true);
dismissDialog();
sendFailure();
}
}, SUCCESS_OR_FAIL_DELAY_MILLIS);
break;
case FINGERPRINT_ERROR_CANCELED:
Log.d(TAG,"Fingerprint has been cancelled");
if(sendCancellation) {
dismissDialog();
if (useEye)
sendCancelForEye();
else
sendCancel();
}
break;
}
}
@Override
public void onAuthenticationHelp(int helpMsgId,
CharSequence helpString) {
Log.d(TAG,"Authentication helper callback");
retryWithError(R.string.test_bio_fingerprint_fingerprint_too_fast);
}
@Override
public void onAuthenticationFailed() {
Log.d(TAG,"Authentication failed callback");
retryWithError(R.string.test_bio_fingerprint_fingerprint_not_recognized);
}
@Override
public void onAuthenticationSucceeded(
FingerprintManager.AuthenticationResult result) {
Log.d(TAG,"Authentication successfull callback");
onAuthenticationSuccess();
}
public void stopListening(boolean sendCancellation) {
this.sendCancellation=sendCancellation;
Log.d(TAG,"stopListening called");
if (cancellationSignal != null) {
cancellationSignal.cancel();
cancellationSignal = null;
}
}
}
此处理程序已放在FingerprintDialog类中,该类扩展了DialogFragment类。
以下代码是初始化处理程序并启动身份验证的地方:
helper = new FingerprintHandler(getContext());
fingerprintManager =(FingerprintManager) getContext().getSystemService(FINGERPRINT_SERVICE);
helper.startAuth(fingerprintManager, null);
编辑2: 如果有人能指出这个实现正常工作的源,并且配置了超时值,那就太棒了。 然后我可以将我的实现与工作实现进行比较,以确定我的实现中是否存在任何问题。 我在android开发者网站或stackoverflow上找不到任何有用的东西。 我也向谷歌提出了一个问题:https://issuetracker.google.com/issues/63629654