Phi*_*ipp 18 android fingerprint
我的应用程序的用户报告说,当我的应用程序正在侦听指纹身份验证(我已经呼叫fingerprintManager.authenticate)并且屏幕已关闭(通过按设备电源开关按钮)时,无法使用指纹解锁设备.
我还可以看到在屏幕关闭时调用onAuthenticationError回调方法,这在我离开活动时不会发生,因为我调用CancellationSignal.cancel()了我的onPause方法.我已经检查过了onPause.
在指纹对话框示例中可以观察到相同的行为(https://github.com/xamarin/monodroid-samples/tree/master/android-m/FingerprintDialog,移植自https://github.com/googlesamples/android- FingerprintDialog)
我该怎么做才能解决这个问题?
编辑:我还尝试注册一个android.intent.action.SCREEN_OFF的广播接收器,它在onPause之后得到通知,因此调用cancel()该接收器不会改变任何东西也就不足为奇了.
我的问题与你的问题类似:如果有人通过按Home键将我的应用程序发送到后台,它仍然可以控制指纹传感器,因此没有其他人可以使用它.从活动onPause()调用取消不起作用:
@Override
protected void onPause() {
super.onPause();
/**
* We are cancelling the Fingerprint Authentication
* when application is going to background
*/
if (fingerprintHelper!=null && fingerprintHelper instanceof AndroidFingerprintHelper){
log.info("canceling AndroidFingerprintHelper dialog");
fingerprintHelper.cancelIdentify();
}
}
Run Code Online (Sandbox Code Playgroud)
你需要调用cancel()你的方法,CancellationSignal在您的活动的onPause()方法,但之前 super.onPause().否则你会收到警告
拒绝你的.package.name.; 不在前台
cancelAuthentication():拒绝您的包名称
我搜索了Android FingerPrint服务的源代码,我发现了这一行:
public void cancelAuthentication(final IBinder token, String opPackageName) {
if (!canUseFingerprint(opPackageName, false /* foregroundOnly */)) {
return;
}
//we don't get here
...
...
}
Run Code Online (Sandbox Code Playgroud)
其中canUseFingerprint实际上检查我们是前景还是否(它做的事情之一):
private boolean canUseFingerprint(String opPackageName, boolean foregroundOnly) {
if (foregroundOnly && !isForegroundActivity(uid, pid)) {
Slog.v(TAG, "Rejecting " + opPackageName + " ; not in foreground");
return false;
}
//we don't get here
}
Run Code Online (Sandbox Code Playgroud)
这样我们就永远不能从后台调用cancelAuth.并且Android认为我们在super.onPause();调用之后就处于后台.经过几个小时的研究,我发现的唯一解决方案是交换取消操作和super.onPause():
@Override
protected void onPause() {
/**
* We are cancelling the Fingerprint Authentication
* when application is going to background
*/
if (fingerprintHelper!=null && fingerprintHelper instanceof AndroidFingerprintHelper){
log.info("canceling AndroidFingerprintHelper dialog");
fingerprintHelper.cancelIdentify();
}
super.onPause();
}
Run Code Online (Sandbox Code Playgroud)
在Android M和N上为我工作.希望这会有所帮助.
我在三星指纹 SDK 中遇到了类似的行为(屏幕锁定或关闭时无法进行身份验证,这不是错误,而是设计使然)。在审查此场景后,我们得出的结论是,最好的方法是为用户创建一个通知,其中包含一个 PendingIntent,该通知将触发您的应用程序并启动指纹身份验证过程。
该通知可以使手机振动/发出蜂鸣声,以便用户收到警报。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
5436 次 |
| 最近记录: |