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

Unable to read any tag D/PersonaManager(): isNFCAllowed #14

Closed RaMb3asT closed 4 years ago

RaMb3asT commented 4 years ago

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:

Syncing files to device SM A320FL...

D/libGLESv2(30340): STS_GLApi : DTS is not allowed for Package : com.oce.flutter_app_nfc

D/libGLESv1(30340): STS_GLApi : DTS is not allowed for Package : com.oce.flutter_app_nfc

W/libc    (30340): It seems that pthread_join() is not invoked or PTHREAD_ATTR_FLAG_DETACHED is not set.

W/libc    (30340):     pthread tid          : 30402

W/libc    (30340):     pthread start_routine: 0xdfda18e7

W/libc    (30340): It seems that pthread_join() is not invoked or PTHREAD_ATTR_FLAG_DETACHED is not set.

W/libc    (30340):     pthread tid          : 30381

W/libc    (30340):     pthread start_routine: 0xdfda18e7

D/ViewRootImpl(30340): ViewPostImeInputStage processPointer 0

D/ViewRootImpl(30340): ViewPostImeInputStage processPointer 1

D/PersonaManager(30340): isNFCAllowed
semlette commented 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?

RaMb3asT commented 4 years ago

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.

semlette commented 4 years ago

Hm, I'm not sure what is causing this.

Could you try the following things

RaMb3asT commented 4 years ago

Alright, I did that but there isn't any change to what is happening or to the logs. Thanks for the quick response anyway!

semlette commented 4 years ago

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?

semlette commented 4 years ago

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 😅

RaMb3asT commented 4 years ago

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

semlette commented 4 years ago

I have pushed some changes to the logs branch. Could you try again?

RaMb3asT commented 4 years ago

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

semlette commented 4 years ago

I have pushed some more changes to the logs branch which should (hopefully) fix the crash.

RaMb3asT commented 4 years ago

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.

semlette commented 4 years ago

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?

semlette commented 4 years ago

I have pushed another update to the logs branch.

RaMb3asT commented 4 years ago

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.

RaMb3asT commented 4 years ago

It still crashes for me with the same output.

semlette commented 4 years ago

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.

RaMb3asT commented 4 years ago

Yes, it was with the NFCDispatchReaderMode().

Here are the images, hope they are sufficient: Screenshot_20190930-092305_NFC Tools Screenshot_20190930-092343_NFC Tools

semlette commented 4 years ago

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.

RaMb3asT commented 4 years ago

Alright, I understand, thank you for the time and effort!