Skip to content

Fix NFC detection for already-present security keys#67

Open
RWebster-Noble wants to merge 1 commit into
mimi89999:mainfrom
RWebster-Noble:nfc-readermode
Open

Fix NFC detection for already-present security keys#67
RWebster-Noble wants to merge 1 commit into
mimi89999:mainfrom
RWebster-Noble:nfc-readermode

Conversation

@RWebster-Noble

@RWebster-Noble RWebster-Noble commented Mar 5, 2026

Copy link
Copy Markdown

Fix NFC tag detection for already-present cards

The credential provider activity was unable to detect NFC security keys that were already present when the authentication flow started. Users had to remove and re-insert their security key for the app to recognize it.

The root cause was that enableForegroundDispatch() only triggers for tags discovered after it's enabled, not for tags already present on the NFC reader. This created a race condition where a key held during the initial prompt would be ignored.

Switch to enableReaderMode() which actively polls for NFC tags, allowing detection of already-present cards. This API (available since API 19) provides more reliable discovery for authentication flows where the user may already be holding their key when the UI appears.

Implications and compatibility:

  • Existing functionality is preserved. Cards tapped after the UI appears continue to work as before.
  • ReaderMode is available on all Android devices running API 19+ (Android 4.4+). The app's minimum SDK is 34, so this is fully supported.
  • A fallback to enableForegroundDispatch() is retained for compatibility, though it is not expected to be used given the app's minimum SDK requirement.
  • The change only affects NFC detection behavior; USB security keys are unaffected.

Testing:

Tested using an Authentrend ATKey.Card NFC card. Verified that:

  • Authentication succeeds when the card is already present on the NFC reader when the prompt appears
  • Authentication continues to work when tapping the card after the prompt appears
  • Card removal and re-presenting still works correctly

Use enableReaderMode() instead of enableForegroundDispatch() to detect
NFC tags already present when the authentication UI appears. This
eliminates the condition where users had to remove and re-insert
their security key.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant