chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 564 forks source link

reading mifare classic 1k card #80

Closed pdesterlich closed 11 years ago

pdesterlich commented 11 years ago

i'm trying to read (and possibly write) data from a mifare classic 1k card, using a samsung s3 with android 4.1.2 i tested all three events (addNdefListener, addTagDiscoveredListener and addMimeTypeListener) but all i can read is tag id using addTagDiscoveredListener.

Other events (ndef and mime) doesn't return me anything (no event fired).

Using other apps (NFC TagInfo, just to say one) i can succesfully read tag data, so i can assume is something within the plugin.

The card is correctly seen as a Mifare Classic

05-08 15:43:03.039: V/NfcPlugin(2443): e.initEvent('tag'); 05-08 15:43:03.039: V/NfcPlugin(2443): e.tag = {"id":[-14,34,-29,-107],"techTypes":["android.nfc.tech.MifareClassic","android.nfc.tech.NfcA","android.nfc.tech.NdefFormatable"]};

Any clue?

don commented 11 years ago

I'm guessing your tag is not NDEF formatted.

I'd use addNdefFormatableListener listener and write a message to the tag. Then you can read it in addNdefListener.

See this example https://gist.github.com/don/5544034

Mifare Classic tags can be unformatted using NFC Tag Writer by NXP. Choose Tools then Clean.

pdesterlich commented 11 years ago

Thank you, that did work. I didn't noticed the addNdefFormatableListener, using your code i can succesfully read & write data on my mifare classic card.