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

Empty tags cannot be read #4

Closed semlette closed 4 years ago

semlette commented 5 years ago

iOS' API doesn't allow to read empty tags but Android's does. Fixable on Android.

movieator commented 4 years ago

Same issue. I need to read the id when tag is emty.

hasanbasri1993 commented 4 years ago

can't write too with the unformatted ndef
any solution ?? @semlette

semlette commented 4 years ago

I have opened pull request #24 which should improve support for empty tags, specifically allowing them to be read on Android and make it easier to check if they're empty using the new NDEFMessage.isEmpty method. I also found out that empty tags can be read on iOS 13 (already supported).

Please check out the PR and see if it fixes the issue for you guys.

hasanbasri1993 commented 4 years ago

your are amazing please update your README.md by example

semlette commented 4 years ago

@movieator does this work for you?

hasanbasri1993 commented 4 years ago

not yet to try, my phone bootloop.

hasanbasri1993 commented 4 years ago

yes this work, but with card formatted ndef. how to write empty and unformatted ndef ?

hasanbasri1993 commented 4 years ago

if (ndef == null) { // tag is not in NDEF format; skip! return; } line 189 NfcInFlutterPlugin.java why, skip ?

Sreadon commented 4 years ago

@hasanbasri1993 I've the "same" problem. I've brand new NFC Tags that are not formatted at all. I'd like to format them as NDEF on scan if they're not but I can't manage to do that.

If the tag is NDEF formatted there is no problem, I can read & write without problem, but I can't do anything if it's "blank".

hasanbasri1993 commented 4 years ago

hello @semlette, any solution for this ??

Sreadon commented 4 years ago

Do you think it's even possible to do something like that? I've read that iPhones only accept NDEF formatted code for reading.

Maybe that's possible to do something like: Scan the TAG => If TAG is recognized (NDEF) then do what you need => If TAG is unrecognized, then format it in NDEF, whatever's on it so after that we can do what we want with it.

semlette commented 4 years ago

Pushed 24c4adcd576fe6cbaf0a17dd90fe6df11c6563a8 to #24.

Tags that doesn't support the Ndef technology, but does support the NdefFormatable technology will now be sent to Flutter. Note that if the tag does not support the Ndef technology, there is absolutely no way to retrieve the ID from the tag.

Sreadon commented 4 years ago

Thanks a lot :) Will test it this afternoon.

Yes, in my case the tags are NdefFormatable, they're just brand new so there is simply "nothing" on them, and I guess a lot of people are in this case.

Sreadon commented 4 years ago

Just tried it, works like a charm for reading :)

However, when writing on a "virgin" tag, I've this error (no error when writing to an already NDEF formatted tag):

E/flutter ( 1788): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(IOError, write to tag error: null, null)

In my case getting the UID is enough, but if it's possible to format "virgin" tags to NDEF automaticaly when the format is unknown, I think that'd be a cool feature.

Thanks again for your work.

semlette commented 4 years ago

Pushed eda624256c41887a85398667839b9d46ee26de92 to #24.

The documentation for NdefFormatable.format() states it must not be called on the main thread. So I have subclassed AsyncTask to FormatTask where NdefFormatable.format() will be called.

I have successfully formatted 2 fresh tags that supported NdefFormatable and not Ndef. However I have ran out of tags that support NdefFormatable so I will not be able to test this any further.

semlette commented 4 years ago

I am going to merge #24 and close this issue since #24 fixed it. If there is a problem, I will reopen the issue.