nfc_in_flutter
nfc_in_flutter copied to clipboard
New tag collected every scan with Android device
Hello,
I am aware there has been other issues discussing this but haven't seemed to be able to find the solution so I thought I'd re-open for the greater good.
How on earth can we stop "new tag collected" from coming up whenever you scan with an android device. I use a basic implementation that simply reads an nfc tag.
NDEFMessage message = await NFC.readNDEF(once: true).first;
I have also tried using it in foreground but the behavior is inconsistent and doesn't work.
NDEFMessage message = await NFC.readNDEF(once: true, readerMode: NFCDispatchReaderMode()).first;
I have done some looking into the intent filters but even with those added it seems to still appear.
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Thanks in advance!
Solution that worked for us:
In Android we changed the launch mode to single task
android:launchMode="singleTask"
Hello Pinteezy , Where can I use this android:launchMode="singleTask" ?
@Pinteezy
This will be in the android-manifest file where you declare your .main activity
have the same issue
Try to set once
parameter to true
and re-listen to the stream value during onDone
. It works for me.
readyToScan() {
stream = NFC.readNDEF(
once: true, // set to true
throwOnUserCancel: false,
.listen(
(NDEFMessage message) async {
}
, onDone: () async {
readyToScan(); // call again readyToScan()
}