Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

### Added
* New `androidReaderModeFlags` parameter for `poll()` method to customize Android Reader Mode behavior
* Allows passing flags like `FLAG_READER_SKIP_NDEF_CHECK` (0x80) for faster tag detection (~500ms improvement)
* Supports `FLAG_READER_NO_PLATFORM_SOUNDS` (0x100) to disable system beeps for custom feedback
* Flags are combined with technology flags using bitwise OR
* Fully backward compatible - optional parameter defaults to null

## 0.0.1

* Initial release
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,26 @@ We use error codes with similar meaning as HTTP status code. Brief explanation a
### Operation Mode

We provide two operation modes: polling (default) and event streaming. Both can give the same `NFCTag` object. Please see [example](example/example.md) for more details.

### Performance Optimization (Android)

For Android applications, you can optimize NFC tag detection performance using the `androidReaderModeFlags` parameter:

```dart
// Skip automatic NDEF discovery for ~500ms faster detection
// and disable platform sounds for custom feedback
const flags = 0x80 | 0x100; // FLAG_READER_SKIP_NDEF_CHECK | FLAG_READER_NO_PLATFORM_SOUNDS

final tag = await FlutterNfcKit.poll(
androidReaderModeFlags: flags,
);
```

Common flags from [`NfcAdapter`](https://developer.android.com/reference/android/nfc/NfcAdapter#enableReaderMode(android.app.Activity,%20android.nfc.NfcAdapter.ReaderCallback,%20int,%20android.os.Bundle)):
- `0x80` - `FLAG_READER_SKIP_NDEF_CHECK`: Skip automatic NDEF discovery, improving detection speed by ~500ms
- `0x100` - `FLAG_READER_NO_PLATFORM_SOUNDS`: Disable system beep/vibration for custom audio/haptic feedback

These flags are particularly useful for applications that:
- Need fast tag detection (e.g., access control, fast payments)
- Implement custom user feedback instead of system sounds
- Use custom NDEF reading logic instead of automatic discovery
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
val timeout = call.argument<Int>("timeout")!!
// technology and option bits are set in Dart code
val technologies = call.argument<Int>("technologies")!!
val readerModeFlags = call.argument<Int>("readerModeFlags")
val extraPresenceDelay = call.argument<Int>("extra_reader_presence_check_delay")

runOnNfcThread(result, "Poll") {
pollTag(nfcAdapter, result, timeout, technologies, extraPresenceDelay)
pollTag(nfcAdapter, result, timeout, technologies, readerModeFlags, extraPresenceDelay)
}
}

Expand Down Expand Up @@ -586,7 +586,7 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {

override fun onDetachedFromActivityForConfigChanges() {}

private fun pollTag(nfcAdapter: NfcAdapter, result: Result, timeout: Int, technologies: Int, extraReaderPresenceCheckDelay: Int?) {
private fun pollTag(nfcAdapter: NfcAdapter, result: Result, timeout: Int, technologies: Int, readerModeFlags: Int?, extraReaderPresenceCheckDelay: Int?) {
pollingTimeoutTask = Timer().schedule(timeout.toLong()) {
try {
if (activity.get() != null) {
Expand All @@ -606,11 +606,19 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
result.success(jsonResult)
}

// Build final flags: combine technology flags with optional reader mode flags
val finalFlags = if (readerModeFlags != null) {
technologies or readerModeFlags
} else {
technologies
}

val options = Bundle()
if (extraReaderPresenceCheckDelay != null) {
options.putInt(EXTRA_READER_PRESENCE_CHECK_DELAY, extraReaderPresenceCheckDelay)
}
nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, options)

nfcAdapter.enableReaderMode(activity.get(), pollHandler, finalFlags, options)
}

private class MethodResultWrapper(result: Result) : Result {
Expand Down
Loading