这个基本的 Android 教程应用程序将打印一条验证指纹认证的 Toast 消息。但它只能验证一次。我希望它能够在应用程序仍在运行时重新验证指纹。我试图在 helper.startAuth() 周围添加一个 while 循环,但它不起作用。我已经引用了几个问题(1、2、3),但没有一个对我有帮助。这是我尝试过的,但它不起作用。
if (cipherInit()) {
cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this);
while(true){
helper.startAuth(fingerprintManager, cryptoObject);
}
}
这是我的 onCreate()。谢谢大家的帮助和指导
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (!keyguardManager.isKeyguardSecure()){
Toast.makeText(this,
"Lock screen security is not enable in Settings", Toast.LENGTH_LONG).show();
return;
}
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED){
Toast.makeText(this,
"Fingerprint authentication permission is not enabled", Toast.LENGTH_LONG).show();
return;
}
if (!fingerprintManager.hasEnrolledFingerprints()){
Toast.makeText(this, "Register at least one fingerprint in Settings", Toast.LENGTH_LONG).show();
return;
}
generateKey();
if (cipherInit()) {
cryptoObject = new FingerprintManager.CryptoObject(cipher);
FingerprintHandler helper = new FingerprintHandler(this);
helper.startAuth(fingerprintManager, cryptoObject);
}
}