Posted on May 25, 2012 by

Read and Write NFC Tags with PhoneGap

The phonegap-nfc plugin allows you to read and write NFC tags from a PhoneGap application using JavaScript.

The plugin originally supported Android. The latest release adds support for Blackberry 7.0.

After installing the plugin into your PhoneGap app (See README) it is easy to start scanning tags.

Create a function that will handle the NFC events.

function onNfc(nfcEvent) {
    // display the tag as JSON

Create the optional success and failure callbacks. These callbacks are for success and failure of adding the listener.

function success(result) {
    console.log("Listening for NFC Messages");
function failure(reason) {
    alert("Failed to add NDEF listener");

Register listener. When the listener is added, the plugin will generate an NFC Event whenever a tag is scanned.

nfc.addNdefListener(onNfc, success, failure);

Deploy the application and scan a tag.

Example Project

The NFC Reader example project has been updated for Blackberry.

nfc_reader_android nfc_reader_blackberry_1 nfc_reader_blackberry_2

More info

The PhoneGap NFC API is documented in the README file.

Kevin wrote Building NFC applications with Android last year. Most of that information still applies.

Tags: , , , , , ,

  • Matt Dunlap
    I have been using the phonegap nfc plugin for a while. Recently, new un-formatted tags would get formatted with the nfc.erase function, but I don't this works anymore.

    I read that there was a bug with NFC formatting nfc tags in android 4.0. It should be fixed, but I still cannot format tags with 4.1?

    Have you noticed, or have any information about this?

    Thank you for the code... It has really helped me with my projects
  • Don Coleman
    I think think we can fix this. EraseTag changed when I added Blackberry support.

    This is probably covered by Issue #20

    If you'd like, add some details on how to reproduce in the comments for that issue.