此basic 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);
}
}
答案 0 :(得分:1)
你不能在onCreate上重复做任何事情。 OnCreate需要完成并继续前进,否则应用程序将被监视器杀死。实际上,你永远不应该在UI线程上反复做任何事情。您需要在另一个线程(或AsyncTask)或某种类型的计时器上执行此操作。