NFC JavaScript Functions

You can find the JavaScript test page at https://www.android-kiosk.com/jstest.htm Just set this as the Kiosk URL on your device to test the functions.

Please note that only URL & text tag types are supported (NDEF).

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"
}
]
Was this article helpful?
Cancel
Thank you!