JS: NFC
NFC JavaScript Functions
NFC Results via Callback
Register for the NFC scan/read callback. Once registered each scan result is sent via nfcScanResult(data), however if the tag is Mifare Ultralight then data from memory are also returned via nfcScanResultMifareUltralight(data) in the form of a JSON array. This callback PERSISTS page loads, so you may need to unregister the callback on other pages if you do not always want the results to be fed back to you via JavaScript (use false as parameter). You must implement nfcScanResultMifareUltralight(data) if any of your NFC tags are Mifare Ultralight. Requires version 2.7.3 (build 254) or higher.
<script>
function registerForNFCScanResults() {
if (typeof Android != 'undefined') {
//tell KB to return results via JS function
Android.useJavaScriptCallbackNFC(true);
}
}
function nfcScanResult(data) {
console.log(data);
}
function nfcScanResultMifareUltralight(data) {
console.log("Result Data:" + data);
}
</script>
Sample JSON output from Mifare Ultralight TAG
[
{
"hex":"0454B46C",
"page":0,
"uid":"0454B44B3C6280"
},
{
"hex":"4A3C6280",
"page":1,
"uid":"0454B44B3C6280"
},
{
"hex":"94480000",
"page":2,
"uid":"0454B44B3C6280"
},
{
"hex":"04030000",
"page":3,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":4,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":5,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":6,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":7,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":8,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":9,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":10,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":11,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":12,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":13,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":14,
"uid":"0454B44B3C6280"
},
{
"hex":"00000000",
"page":15,
"uid":"0454B44B3C6280"
}
]
Updated on: 18/07/2019
Thank you!