if (fingerprintManager.isHardwareDetected()) {
//判断屏幕锁是否正常。想要使用指纹识别的话,必须首先使能屏幕锁才行,
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
// this device is secure..
/* Return whether the keyguard is secured by a PIN, pattern or password or a SIM card
* is currently locked.*/
// if (keyguardManager.isKeyguardSecure()) {
//6.0中,普通app要想使用指纹识别功能的话,用户必须首先在setting中注册至少一个指纹才行,否则是不能使用的
if (fingerprintManager.hasEnrolledFingerprints()) {
// start fingerprint auth here.
try {
// CryptoObjectHelper cryptoObjectHelper = new CryptoObjectHelper();
// 创建一个取消信号,初始化时是非取消状态
if (cancellationSignal == null) {
cancellationSignal = new CancellationSignal();
}
if (cancellationSignal.isCanceled()) {
cancellationSignal = new CancellationSignal();
}
//指纹认证回调接口
myAuthCallback = new MyAuthCallback(context, handler);
//一直扫描指纹硬件。
fingerprintManager.authenticate(null, cancellationSignal, 0, myAuthCallback, null);
} catch (Exception e) {
}
}
以上是指纹验证的主要代码,写在Activity中是可以正常验证的,写在Service却拿不到返回值,不知道是什么原因?