Closed RaMb3asT closed 4 years ago
I don't know anything about reading RFID tags using NFC on Android, except that it is possible. Could you tell me a bit more about your tags, specifically if they're empty or if their content conform to the NDEF standard?
As far as I am concerned, they conform to the NDEF standard as I am able to scan them using NFC readers from the App store. The tags are attached to ink containers and contain data regarding the contents of the container like product type, ink color, production date, etc. Each of these fields is placed on a separate block of the memory content of the tag. The tech they use is NfcV.
Hm, I'm not sure what is causing this.
Could you try the following things
Open example/lib/main.dart
and add the readerMode: NFCDispatchReaderMode()
argument to readNDEF()
on line 28.
Open android/src/main/java/me/andisemler/nfc_in_flutter/NfcInFlutterPlugin.java
and add Log.e(LOG_TAG. "!! NOT NDEF !!")
under line 164 and line 205.
After that, try scanning some tags and see if the logs contains NfcInFlutterPlugin: !! NOT NDEF !!
Alright, I did that but there isn't any change to what is happening or to the logs. Thanks for the quick response anyway!
I've just created a new branch logs
which has a few more log statements. Could you checkout the branch and see if anything different happens?
Also, try adding
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
to your Activity
in your AndroidManifest.xml
and setting the readerMode
to NFCDispatchReaderMode()
again.
Haven't a clue if this will change anything but one can always hope 😅
Okay, I think this might be the problem - the tag format not being supported, from the logs:
W/NfcInFlutterPlugin( 9212): received unsupported ACTION_TAG_DISCOVERED intent
I have pushed some changes to the logs
branch. Could you try again?
Weird, the app crashes with that as a log:
E/AndroidRuntime(22673): FATAL EXCEPTION: main
E/AndroidRuntime(22673): Process: com.oce.flutter_app_nfc, PID: 22673
E/AndroidRuntime(22673): java.lang.NullPointerException: Attempt to invoke virtual
method 'android.nfc.NdefRecord[] android.nfc.NdefMessage.getRecords()' on a null object reference
E/AndroidRuntime(22673): at me.andisemler.nfc_in_flutter.NfcInFlutterPlugin.formatNDEFMessageToResult
(NfcInFlutterPlugin.java:217)
E/AndroidRuntime(22673): at me.andisemler.nfc_in_flutter.NfcInFlutterPlugin.handleNDEFTagFromIntent
(NfcInFlutterPlugin.java:211)
E/AndroidRuntime(22673): at me.andisemler.nfc_in_flutter.NfcInFlutterPlugin.onNewIntent
(NfcInFlutterPlugin.java:203)
Edit:
Also, now I checked that on another tag it does not crash but I get:
W/NfcInFlutterPlugin(11649): tag does not support NDEF technology
I have pushed some more changes to the logs
branch which should (hopefully) fix the crash.
Unfortunately, it still has the same behaviour. Crash on one tag, same output on the other. The one, it crashes on has an empty/weirdly written in data on the first memory block.
I think I see why it still crashes, but I'm not sure why the tag won't work.
onNewIntent
receiving the action NfcAdapter.ACTION_TAG_DISCOVERED
and not NfcAdapter.ACTION_NDEF_DISCOVERED
would suggest Android didn't recognise the content as a NDEF message, and then crashing because of a mistake in my code.
Have you tried using other NFC libraries for Flutter to see if it works with them?
I have pushed another update to the logs branch.
I will check it out again on Monday when I go back to work. In regards to other libraries, I tried flutter_nfc_reader and nfc, but with no success either.
It still crashes for me with the same output.
How peculiar...
Was this with the NFCDispatchReaderMode()
?
Also, could you try scanning the tag using the NFC Tools app and send me a screenshot (either here or by e-mail). Specifically the section with the message records. If the records contain any sensitive information, just blur it out. I am only interested in the media types of the records.
Yes, it was with the NFCDispatchReaderMode()
.
Here are the images, hope they are sufficient:
This explains a few things.
The tag doesn't support the "android.nfc.tech.Ndef
technology" (see Technologies available in the first screenshot) which is a deal breaker, as it is currently required by nfc_in_flutter.
The NdefFormatable
only allows writing NDEF messages, but not retrieving.
As it stands right now, your tag is not usable with nfc_in_flutter, as a new API would have to be introduced to support the NfcV
technology.
I do have plans to add such API in the future, but I'm working on a new release that has top priority. Plus I don't actually have any cards to test it with, so I'll have to acquire some first.
Alright, I understand, thank you for the time and effort!
To test out reading RFID tags, I used the example code provided on the repository. The application runs but when I press on Start reading and consecutively try to scan a tag, I get a response from the device that the tag is found(usually vibration), however the scanned tag does not appear on the screen.
Here is an overview of the log: