Overview
This API is used to enable/disable the NFC Adapter and read NFC Tags. The EzNFC API is currently supported on Android only.
Enabling the API
There are two ways to enable Enterprise Browser APIs:
- Include all 'ebapi' modules
- Include only the required API modules
Both methods are explained below.
Either way, the included files will be from:
/Enterprise Browser/JavaScript Files/Enterprise Browser
,
a directory on the computer that contains the Enterprise Browser installation.
Include all JS API modules
To include all JavaScript APIs, copy the ebapi-modules.js
file to a location accessible by your app's files and include the JavaScript modules file in your app. For instance, to include the modules file in your index.html
, copy the file to the same directory as your index.html and add the following line to the HEAD section of your index.html file:
<script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script>
This will define the EB class within the page. Note that the path for this file is relative to the current page (index.html). Any page on which the modules are required will need to have the required .js file(s) included in this fashion.
Include only the required modules
To include individual APIs, you must first include the ebapi.js
in your HTML, and then the additional required API file(s). For instance, to use the EzNFC API, add the following code to the HTML file(s). Again, this assumes that relevant API files have been copied to the same directory as the HTML.
<script type="text/javascript" charset="utf-8" src="ebapi.js"></script>
<script type="text/javascript" charset="utf-8" src="eb.eznfc.js"></script>
In the code lines above, notice that
ebapi.js
is included first, followed byeb.eznfc.js
, which is the EzNFC API for Enterprise Browser. This coding is required on each HTML page whenever an individual API will be called from that page.
Methods
disableRead()
Disables NFC read of the application.
Parameters
- callback : CallBackHandler
Returns
Synchronous Return:
- Void
Platforms
- Android
Method Access:
- Class Method: This method can only be accessed via the API class object.
EB.EzNFC.disableRead()
enableAdapter()
Navigates to device NFC Adapter settings screen if device's NFC Adapter is not enabled.
Parameters
- callback : CallBackHandler
Returns
Synchronous Return:
- Void
Platforms
- Android
Method Access:
- Class Method: This method can only be accessed via the API class object.
EB.EzNFC.enableAdapter()
enableRead()
Enables NFC read of the application if device supports NFC.
Parameters
- callback : CallBackHandler
Callback
Async Callback Returning Parameters: HASH
- Type : STRING
The Type of NFC Tag that has been read
- ID : STRING
The ID of the Tag that has been read
- Payload : STRING
Payload is the data overall data of NFC Tag
- TNF : STRING
TNF is last 3 bits of Payload
- EncodingFormat : STRING
Text encoding format applied
- data : STRING
The String data that is read from Tag
- TagIDHexa : STRING
NFC Tag id in Hexacode
Returns
Synchronous Return:
- Void
Platforms
- Android
Method Access:
- Class Method: This method can only be accessed via the API class object.
EB.EzNFC.enableRead()
Properties
isEnabled
Type
BOOLEAN
Description
Detects whether the NFC Adapter is enabled. Returns true if the NFC Adapter is enabled.
Params
Default: false
Access
- Class: This property can only be accessed via the API class object.
EB.EzNFC.isEnabled
Platforms
- Android
isSupported
Type
BOOLEAN
Description
Determines whether NFC is supported on the device. Returns true if NFC is supported.
Params
Default: false
Access
- Class: This property can only be accessed via the API class object.
EB.EzNFC.isSupported
Platforms
- Android
Remarks
General
- NFC reads are only possible when the application is in the foreground.
- It is mandatory to disable default NFC application of the device before using this API.
- The APIs are designed to read NON-Secure NFC Tags.
- The NFC APIs are designed to work in Reader Mode only.
Recommended order of API calls
- EB.EzNFC.isSupported;
- EB.EzNFC.isEnabled;
- EB.EzNFC.enableAdapter();
- EB.EzNFC.enableRead();
- EB.EzNFC.disableRead();
Examples
Usage Guide
This example shows how to use the EzNFC API:
<html>
<head>
<title>Enterprise Browser NFC API Test</title>
<script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script>
<script type="text/javascript">
/*
EB.EzNFC.isSupported
Property to check whether NFC is supported on the device.
Return
true - if supported
false - if not supported
*/
function isNfcSupported()
{
var x=EB.EzNFC.isSupported;
document.getElementById("demo1").innerHTML = x;
}
/*
EB.EzNFC.isEnabled
Property to check whether NFC Adapter is enabled on the device.
Return
true - if enabled
false - if not enabled
*/
function isNfcEnabled()
{
var x=EB.EzNFC.isEnabled;
document.getElementById("demo2").innerHTML = x;
}
/*
EB.EzNFC.enableAdapter();
Method to enable the NFC Adapter. Invoking this method brings up the Device settings Activity so user can manually enable the NFC Adapter.
Calling this method has no effect if NFC Adapter is already enabled.
*/
function EnableNfcAdapter()
{
EB.EzNFC.enableAdapter();
}
/*
enableRead(enableNfcCallback1)
Method to enable NFC Tag Reading.
*/
function EnableNfcRead()
{
EB.EzNFC.enableRead(enableNfcCallback1);
}
/*
disableRead();
Method to disable NFC Tag Reading.
*/
function DisableNfcRead()
{
EB.EzNFC.disableRead();
/* Clearing the div of previously read data*/
document.getElementById("demo5").innerHTML = "";
}
/*
enableRead(enableNfcCallback1).
User-defined callback with the enableRead() method.
Gets fired when NFC Tag is Read.
Returns Tag
ID
Type
TNF
Payload
EncodingFormat
Result
*/
function enableNfcCallback1(dat) {
var ID = dat.id;
var Type = dat.type;
var TNF = dat.tnf;
var Payload = dat.payload;
var EncodingFormat = dat.encodingformat;
var Result = dat.result;
var TagIDHexa = dat.tagidhexa;
var ShowData = "ID:" + ID + "<BR>Type:" + Type + "<BR>TNF:" + TNF + "<BR>Payload:" + Payload + "<BR>EncodingFormat:" + EncodingFormat + "<BR>Result:" + Result + "<BR>TagIDHexa: " + TagIDHexa ;
document.getElementById("demo5").innerHTML = ShowData;
}
</script>
</head>
<body>
<h2 align="center">Enterprise Browser NFC API Test</h2>
<hr>
<br>
<DIV>
<table border=1>
<tr>
<td>
<button onclick="isNfcSupported();">isSupported</button>:
</td>
<td><div id="demo1"></div></td>
</tr>
<tr>
<td>
<button onclick="isNfcEnabled();">isEnabled</button>:
</td>
<td><div id="demo2"></div></td>
</tr>
<tr>
<td colspan=2>
<button onclick="EnableNfcAdapter();">enableAdapter</button>:
</td>
</tr>
<tr>
<td colspan=2>
<button onclick="EnableNfcRead();">enableRead</button>:</td>
</td>
</tr>
<tr>
<td colspan=2>
<button onclick="DisableNfcRead();">disableRead</button>:</td>
</td>
</tr>
</table>
</DIV>
<DIV id="demo5"></DIV>
</body>
</html>