ApacheCon North America - April 7, 2014
Presented by Don Coleman / @doncoleman
Tags hold a tiny amount of data
Think bytes
not kilobytes, megabytes, or gigabytesData for the user application
Indicates the structure of the value of the type field
Identifier describing the type of the Payload
Must follow rules implied by TNF
One or more NDEF Records
Contains a payload of data
Information describing the payload
$ cordova create nfc com.example.nfc NFC
$ cd nfc
$ cordova platform add android
$ cordova plugin add \
com.chariotsolutions.nfc.plugin
nfc.addNdefListener(
eventListener,
success,
failure
);
nfc.addNdefListener(
app.onNfc,
success,
failure
);
onNfc: function(nfcEvent) {
var tag = nfcEvent.tag,
ndefMessage = tag.ndefMessage;
alert(JSON.stringify(ndefMessage));
}
util.isType(record, tnf, type);
if (util.isType(rec, TNF_WELL_KNOWN, RTD_URI)) {
value = ndef.uriHelper.decodePayload(payload);
} else if (util.isType(rec, TNF_WELL_KNOWN, RTD_TEXT)) {
value = ndef.textHelper.decodePayload(payload);
} else if // ...
Must call write within an event handler
var message = [
ndef.uriRecord("http://cordova.io")
];
ndef.write(message, success, failure);
var message = [
ndef.uriRecord("http://cordova.io"),
ndef.textRecord("hello, world")
];
ndef.write(message, success, failure);
var message = [
ndef.uriRecord("http://cordova.io")
];
ndef.share(message, success, failure);
takePicture: function() {
navigator.camera.getPicture(
app.onCameraSuccess, failure);
},
onCameraSuccess: function (imageURI) {
nfc.handover(imageURI, success, fail);
}
<intent-filter>
<action android:name=
"android.nfc.action.NDEF_DISCOVERED"/>
<data android:mimeType="text/plain"/>
<category android:name=
"android.intent.category.DEFAULT"/>
</intent-filter>
Tomorrow, Tuesday April 8, 2014
10:30am - 5:30pm
McCourt room at ApacheCon
Don Coleman

Writing NFC Apps with Apache Cordova by Don Coleman
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at https://github.com/don/slides/tree/gh-pages/2014-04-07-apachecon-nfc.