0

Why FingerprintManager.AuthenticationCallback not responding in foreground service?

Code

//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);

It's working well if the activity was running but if I destroy the actvity, the listeners above not responding, Why?

Taha Sami
  • 1,565
  • 1
  • 16
  • 43

1 Answers1

0

Finally, After hours of trying I found the problem, The solution is you must create AccessibilityService and enable the permission from settings, After enabling the permission, Callback will work.

Taha Sami
  • 1,565
  • 1
  • 16
  • 43