Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap NFC not working

I followed the instructions at the phonegap-nfc project page to install the nfc plugin for my phonegap project.
On starting the application, I do see the Waiting for NDEF tag alert. However, on tapping an NFC card to the phone, I just hear the failed NFC sound (you can hear that sound in this video). I'm nt sure whats wrong here.

The code is exactly the same as instructed at the first link above. For brevity, I'll copy the code here as well:
My index.js has-

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    // Read NDEF formatted NFC Tags
    nfc.addNdefListener (
        function (nfcEvent) {
            var tag = nfcEvent.tag,
                ndefMessage = tag.ndefMessage;

            // dump the raw json of the message
            // note: real code will need to decode
            // the payload from each record
            alert(JSON.stringify(ndefMessage));

            // assuming the first record in the message has 
            // a payload that can be converted to a string.
            alert(nfc.bytesToString(ndefMessage[0].payload).substring(3));
        }, 
        function () { // success callback
            alert("Waiting for NDEF tag");
        },
        function (error) { // error callback
            alert("Error adding NDEF listener " + JSON.stringify(error));
        }
    );
},
like image 752
Urban Avatar asked Mar 26 '26 09:03

Urban


1 Answers

The plugin only allows Writing/Reading NDEF tags because this kind of operations is quite easy.

NFC cards can be much more complex and need to follow specific structures and encryption depending on the kind of card. And sometimes requires rending commands to the card and waiting for a response following complex protocols.

In your case a Mifare classic card, you have to know a key to be able to read datas.

For those reasons a generic plugin can not allow to read any kind of NFC cards.

The chariotsolutions plugin allows full access to NDEF tags but only lets you get the tag ID for other cards (in that case use nfc.addTagDiscoveredListener instead)

To perform more specific operations, may make your own plugin starting from this one.

To check what kind of card you have you can use This app

You can also check the Google page about NFC for more reference, or this interesting doc from Motorola.

like image 141
QuickFix Avatar answered Mar 27 '26 23:03

QuickFix