【问题标题】:Why FingerprintManager.AuthenticationCallback not responding in foreground service?为什么 FingerprintManager.AuthenticationCallback 在前台服务中没有响应?
【发布时间】: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


    【解决方案1】:

    最后,经过几个小时的尝试,我发现了问题,解决方法是你必须创建AccessibilityService并从设置中启用权限,启用权限后,回调将起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 2011-04-02
      • 2016-02-24
      • 1970-01-01
      • 2015-02-26
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多