【发布时间】:2021-09-11 07:23:51
【问题描述】:
为什么FingerprintManager.AuthenticationCallback 在前台服务没有响应?
代码
//Inside onStartCommand method
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
windowManager.addView(view, layoutParams);
startForeground(NotificationControl.notificationId, NotificationControl.builderOfNotification(this, false).build());
FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);
FingerprintManager.AuthenticationCallback authenticationCallback = new FingerprintManager.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
Toast.makeText(ForegroundService.this, "1", Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
super.onAuthenticationHelp(helpCode, helpString);
Toast.makeText(ForegroundService.this, "2", Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(ForegroundService.this, "3", Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(ForegroundService.this, "4", Toast.LENGTH_SHORT).show();
}
};
fingerprintManager.authenticate(null, null, 0, authenticationCallback, null);
如果活动正在运行,它运行良好,但如果我破坏活动,上面的侦听器没有响应,为什么?
【问题讨论】:
标签: android android-service android-fingerprint-api