nfc_in_flutter icon indicating copy to clipboard operation
nfc_in_flutter copied to clipboard

New tag collected every scan with Android device

Open Pinteezy opened this issue 4 years ago • 6 comments

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 avatar Jan 28 '21 12:01 Pinteezy

Solution that worked for us:

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

Pinteezy avatar Jan 31 '21 13:01 Pinteezy

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

mazensabouni avatar Mar 27 '21 11:03 mazensabouni

@Pinteezy

mazensabouni avatar Mar 27 '21 11:03 mazensabouni

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

Pinteezy avatar Mar 27 '21 11:03 Pinteezy

have the same issue

kasvith avatar Apr 20 '21 14:04 kasvith

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

haizadvnet avatar Nov 02 '22 09:11 haizadvnet