I would like to read an NFC
tag's UID
, tags don't have any ndef
message or anything (empty), just UID
. It's easy to do on Android, but Phonegap development is way faster so I would like to know if it's possible to get it working on Phonegap, probably using the phonegap-nfc plugin.
The phonagap-nfc plugin will allow you to read the tag's UID
.
nfc.addTagDiscoveredListener()
is good if you need the tag id. As of phonegap-nfc-0.4.0
the tag id is also included with the NDEF
listeners when it is available.
You can convert the id to a hex string for display with nfc.bytesToHexString(tag.id)
function ready() {
function onNfc(nfcEvent) {
var tag = nfcEvent.tag;
var tagId = nfc.bytesToHexString(tag.id);
alert(tagId);
}
function win() {
console.log("Listening for NFC Tags");
}
function fail(error) {
alert("Error adding NFC listener");
}
nfc.addTagDiscoveredListener(onNfc, win, fail);
}
function init() {
document.addEventListener('deviceready', ready, false);
}
The answer is in your question: yes, use the NFC plugin. Add a callback for any tag with nfc.addTagDiscoveredListener()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With