Phonegap NFC not working

I followed the instructions on the phonegap-nfc project page to install the nfc plugin for my phonegap project.
I see a warning when starting the application Waiting for NDEF tag

. However, when I press the NFC card on the phone, I just hear the NFC sound you heard (you can hear that sound in this video ). I'm not sure what is wrong here.

The code is exactly the same as in the first link above. For brevity, I'll also copy the code:
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));
        }
    );
},

      

+3


source to share


1 answer


Only the plugin allows you to write / read NDEF tags, because this kind of operation is quite simple.

NFC cards can be much more complex and must track specific structures and encryption depending on the type of card. And sometimes a command is required to markup to the map and wait for a response using complex protocols.

In your case, the classic Mifare card, you have to know the key to read the data.

For these reasons, the generic plugin does not allow any NFC cards to be read.



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

To perform more specific operations, you can make your own plugin starting here.

To check which card you have you can use This application

You can also check Google's NFC page for more information or this interesting document from Motorola ..

+5


source







All Articles