semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
120 stars 119 forks source link

New tag collected every scan with Android device #74

Open Pinteezy opened 3 years ago

Pinteezy commented 3 years ago

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!

Pinteezy commented 3 years ago

Solution that worked for us:

In Android we changed the launch mode to single task android:launchMode="singleTask"

mazensabouni commented 3 years ago

Hello Pinteezy , Where can I use this android:launchMode="singleTask" ?

mazensabouni commented 3 years ago

@Pinteezy

Pinteezy commented 3 years ago

This will be in the android-manifest file where you declare your .main activity

kasvith commented 3 years ago

have the same issue

haizadvnet commented 1 year ago

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()
            }