在我的应用中,我建立了一个生物识别身份验证,它将向用户显示一个屏幕,并在“启动屏幕”之后直接询问其指纹/ PIN。
public abstract class BaseActivity extends AppCompatActivity {
...
protected boolean authenticate() {
if (isBiometricEnabled) {
final KeyguardManager systemService = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (systemService == null) return false;
if (systemService.isKeyguardSecure()) {
final Intent confirmDeviceCredentialIntent = systemService
.createConfirmDeviceCredentialIntent(getString(R.string.app_name_long), getAuthBodyText());
startActivityForResult(confirmDeviceCredentialIntent, REQUEST_CODE_BIOMETRIC_AUTHENTICATION);
} else {
AlertDialog dialog = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle).create();
dialog.setTitle(R.string.security_dialog_title);
dialog.setMessage(getString(R.string.security_dialog_message));
dialog.setCancelable(false);
dialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.security_dialog_button), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
String action;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
action = Settings.ACTION_FINGERPRINT_ENROLL;
} else {
action = Settings.ACTION_SECURITY_SETTINGS;
}
intent.setAction(action);
startActivityForResult(intent, REQUEST_CODE_SETUP_BIOMETRIC);
}
});
dialog.show();
}
return true;
}
return false;
}
}
在我的SplashActivity中
public class SplashActivity extends BaseActivity {
public void authenticateAndNavigate() {
if (!authenticate()) {
navigateToHome();
}
}
}
这种方法效果很好。但是,我想更改行为,以使用户每次在应用程序进入后台并再次返回时都被迫输入其指纹/ PIN。
我尝试将其添加到onResume()
内的BaseActivity
方法中,但是它没有用,因为生物识别活动将显示onPause()
是我的{{1} },一旦用户完成操作,BaseActivity
将再次被调用,该应用将陷入仅显示生物识别活动的循环中。
还有其他想法如何实现吗?