MifareClassicTool icon indicating copy to clipboard operation
MifareClassicTool copied to clipboard

Need help about initialize the NFC

Open zhxst opened this issue 1 year ago • 4 comments

Hey, this MCT tool is very cool. I'm learning to create a flutter plugin for simple use. Currently I just learing form your source code for simple usage like read and write card.

The card is 4 bytes magic card, and works well with MCT. But I use my demo code, it success to detect the card, but fail on authenticate the key. And here is the STRANGE thing. After I use the MCT to detect the card, my demo can suddenly successfully auth the key and write the block. It works until I reboot the phone.

So, what am I missing before authenticating the key? Or is there something special to initialize when detect the card? Any advice will be very helpful. Thank you.

zhxst avatar Sep 11 '22 07:09 zhxst

It's a plugin, so no interface. I use nfcAdapter.enableReaderMode. When tag detected I use McReader.patchTag, then Common.checkMifareClassicSupport, then MCReader.get(tag), then use reader.connect() and then reader.writeBlock.

zhxst avatar Sep 11 '22 08:09 zhxst

After tried many times, it comes out that, I need to detect a card outside my app any where. Then I can auth the card inside the app. So weird.

zhxst avatar Sep 13 '22 08:09 zhxst

Found answer on stackoverflow. So it's because enableReaderMode is somehow different from enableForegrounDispatch, which cause patchTag fail.

zhxst avatar Sep 16 '22 01:09 zhxst

Me again. The major problem is actually missing Intent Filter about ACTION_TECH_DISCOVERED. So both enableReaderMode and enableForegrounDispatch works. Still, the problem about last comment on stack overflow is maybe exist. So I decide to change to enableForegrounDispatch for possibly better Compatibility.

zhxst avatar Sep 17 '22 03:09 zhxst

Hi. Finally found some time to look at MCT's issue list. What a journey you had. Yes, lots of pitfalls. And yes, enableReaderMode is something completely different than foreground dispatching.

Not sure if there is anything left I can help you with. If so, say so.

Best of luck!

ikarus23 avatar Sep 28 '22 18:09 ikarus23