如何在 onCreate() 中重复验证指纹
How To Repeatedly Authenticate FingerPrint in onCreate()
这 basic Android tutorial app is going to print a Toast message verifying the fingerprint authentication. But it is only able to authenticate once. I want it to be able to reauthenticate fingerprint whenever the app is still running. I've tried to add a while loop wrapping around the helper.startAuth() and it is not working. I've referenced several questions (1,2,3) 但其中 none 正在帮助我。这是我试过的方法,但没有用。
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);
}
}
您不能在 onCreate 中重复执行任何操作。 OnCreate 需要完成并继续,否则应用程序将被看门狗杀死。事实上,你永远不应该在 UI 线程上重复做任何事情。您需要在另一个线程(或 AsyncTask)或某种计时器上执行此操作。
这 basic Android tutorial app is going to print a Toast message verifying the fingerprint authentication. But it is only able to authenticate once. I want it to be able to reauthenticate fingerprint whenever the app is still running. I've tried to add a while loop wrapping around the helper.startAuth() and it is not working. I've referenced several questions (1,2,3) 但其中 none 正在帮助我。这是我试过的方法,但没有用。
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);
}
}
您不能在 onCreate 中重复执行任何操作。 OnCreate 需要完成并继续,否则应用程序将被看门狗杀死。事实上,你永远不应该在 UI 线程上重复做任何事情。您需要在另一个线程(或 AsyncTask)或某种计时器上执行此操作。