|
| 1 | +#EzNFC |
| 2 | + |
| 3 | + |
| 4 | +## Overview |
| 5 | +This API is used to enable/disable the NFC Adapter and read NFC Tags. **The EzNFC API is currently supported on Android only**. |
| 6 | +## Enabling the API |
| 7 | +There are two ways to enable Enterprise Browser APIs: |
| 8 | + |
| 9 | +* Include all 'ebapi' modules |
| 10 | +* Include only the API modules you need |
| 11 | + |
| 12 | +Both methods are explained below. |
| 13 | + |
| 14 | +Either way, the included files will be from: |
| 15 | +`/Enterprise Browser/JavaScript Files/Enterprise Browser`, |
| 16 | +a directory on the computer that contains the Enterprise Browser installation. |
| 17 | + |
| 18 | +### Include all JS API modules |
| 19 | +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: |
| 20 | + |
| 21 | + :::html |
| 22 | + <script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script> |
| 23 | + |
| 24 | +> 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. |
| 25 | +
|
| 26 | +### Include only the modules you need |
| 27 | + |
| 28 | +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. |
| 29 | + |
| 30 | + :::html |
| 31 | + <script type="text/javascript" charset="utf-8" src="ebapi.js"></script> |
| 32 | + <script type="text/javascript" charset="utf-8" src="eb.eznfc.js"></script> |
| 33 | + |
| 34 | +> In the code lines above, notice that `ebapi.js` is included first, followed by `eb.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**. |
| 35 | +
|
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +##Methods |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +### disableRead() |
| 44 | +Disables NFC read of the application. |
| 45 | + |
| 46 | +####Parameters |
| 47 | +<ul><li>callback : <span class='text-info'>CallBackHandler</span></li></ul> |
| 48 | + |
| 49 | +####Returns |
| 50 | +Synchronous Return: |
| 51 | + |
| 52 | +* Void |
| 53 | + |
| 54 | +####Platforms |
| 55 | + |
| 56 | +* Android |
| 57 | + |
| 58 | +####Method Access: |
| 59 | + |
| 60 | +* Class Method: This method can only be accessed via the API class object. |
| 61 | + * <code>EB.EzNFC.disableRead()</code> |
| 62 | + |
| 63 | + |
| 64 | +### enableAdapter() |
| 65 | +Navigates to device NFC Adapter settings screen if device's NFC Adapter is not enabled. |
| 66 | + |
| 67 | +####Parameters |
| 68 | +<ul><li>callback : <span class='text-info'>CallBackHandler</span></li></ul> |
| 69 | + |
| 70 | +####Returns |
| 71 | +Synchronous Return: |
| 72 | + |
| 73 | +* Void |
| 74 | + |
| 75 | +####Platforms |
| 76 | + |
| 77 | +* Android |
| 78 | + |
| 79 | +####Method Access: |
| 80 | + |
| 81 | +* Class Method: This method can only be accessed via the API class object. |
| 82 | + * <code>EB.EzNFC.enableAdapter()</code> |
| 83 | + |
| 84 | + |
| 85 | +### enableRead() |
| 86 | +Enables NFC read of the application if device supports NFC. |
| 87 | + |
| 88 | +####Parameters |
| 89 | +<ul><li>callback : <span class='text-info'>CallBackHandler</span></li></ul> |
| 90 | + |
| 91 | +####Callback |
| 92 | +Async Callback Returning Parameters: <span class='text-info'>HASH</span></p><ul><ul><li>Type : <span class='text-info'>STRING</span><p>The Type of NFC Tag that has been read </p></li><li>ID : <span class='text-info'>STRING</span><p>The ID of the Tag that has been read </p></li><li>Payload : <span class='text-info'>STRING</span><p>Payload is the data overall data of NFC Tag </p></li><li>TNF : <span class='text-info'>STRING</span><p>TNF is last 3 bits of Payload </p></li><li>EncodingFormat : <span class='text-info'>STRING</span><p>Text encoding format applied </p></li><li>data : <span class='text-info'>STRING</span><p>The String data that is read from Tag </p></li><li>TagIDHexa : <span class='text-info'>STRING</span><p>NFC Tag id in Hexacode </p></li></ul></ul> |
| 93 | + |
| 94 | +####Returns |
| 95 | +Synchronous Return: |
| 96 | + |
| 97 | +* Void |
| 98 | + |
| 99 | +####Platforms |
| 100 | + |
| 101 | +* Android |
| 102 | + |
| 103 | +####Method Access: |
| 104 | + |
| 105 | +* Class Method: This method can only be accessed via the API class object. |
| 106 | + * <code>EB.EzNFC.enableRead()</code> |
| 107 | + |
| 108 | + |
| 109 | +##Properties |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +###isEnabled |
| 114 | + |
| 115 | +####Type |
| 116 | +<span class='text-info'>BOOLEAN</span> |
| 117 | +####Description |
| 118 | +Detects whether the NFC Adapter is enabled. Returns true if the NFC Adapter is enabled. |
| 119 | +####Params |
| 120 | +<p><strong>Default:</strong> false</p> |
| 121 | +####Access |
| 122 | + |
| 123 | + |
| 124 | +* Class: This property can only be accessed via the API class object. |
| 125 | + * <code>EB.EzNFC.isEnabled</code> |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +####Platforms |
| 130 | + |
| 131 | +* Android |
| 132 | + |
| 133 | +###isSupported |
| 134 | + |
| 135 | +####Type |
| 136 | +<span class='text-info'>BOOLEAN</span> |
| 137 | +####Description |
| 138 | +Determines whether NFC is supported on the device. Returns true if NFC is supported. |
| 139 | +####Params |
| 140 | +<p><strong>Default:</strong> false</p> |
| 141 | +####Access |
| 142 | + |
| 143 | + |
| 144 | +* Class: This property can only be accessed via the API class object. |
| 145 | + * <code>EB.EzNFC.isSupported</code> |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | +####Platforms |
| 150 | + |
| 151 | +* Android |
| 152 | + |
| 153 | +##Remarks |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +###General |
| 158 | + |
| 159 | + |
| 160 | +1. NFC reads are only possible when the application is in the foreground. |
| 161 | +2. It is mandatory to disable default NFC application of the device before using this API. |
| 162 | +3. The APIs are designed to read NON-Secure NFC Tags. |
| 163 | +4. The NFC APIs are designed to work in Reader Mode only. |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | +###Recommended order of API calls |
| 168 | + |
| 169 | + |
| 170 | +1. EB.EzNFC.isSupported; |
| 171 | +2. EB.EzNFC.isEnabled; |
| 172 | +3. EB.EzNFC.enableAdapter(); |
| 173 | +4. EB.EzNFC.enableRead(); |
| 174 | +5. EB.EzNFC.disableRead(); |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +##Examples |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | +###Usage Guide |
| 183 | +This example shows how to use the EzNFC API: |
| 184 | +<pre><code>:::javascript |
| 185 | +<html> |
| 186 | +<head> |
| 187 | + <title>Enterprise Browser NFC API Test</title> |
| 188 | +<script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script> |
| 189 | +<script type="text/javascript"> |
| 190 | +/* |
| 191 | +EB.EzNFC.isSupported |
| 192 | +Property to check whether NFC is supported on the device. |
| 193 | +Return |
| 194 | + true - if supported |
| 195 | + false - if not supported |
| 196 | +*/ |
| 197 | +function isNfcSupported() |
| 198 | +{ |
| 199 | + var x=EB.EzNFC.isSupported; |
| 200 | + document.getElementById("demo1").innerHTML = x; |
| 201 | +} |
| 202 | +/* |
| 203 | +EB.EzNFC.isEnabled |
| 204 | +Property to check whether NFC Adapter is enabled on the device. |
| 205 | +Return |
| 206 | + true - if enabled |
| 207 | + false - if not enabled |
| 208 | +*/ |
| 209 | +function isNfcEnabled() |
| 210 | +{ |
| 211 | + var x=EB.EzNFC.isEnabled; |
| 212 | + document.getElementById("demo2").innerHTML = x; |
| 213 | +} |
| 214 | +/* |
| 215 | +EB.EzNFC.enableAdapter(); |
| 216 | +Method to enable the NFC Adapter. Invoking this method brings up the Device settings Activity so user can manually enable the NFC Adapter. |
| 217 | +Calling this method has no effect if NFC Adapter is already enabled. |
| 218 | +*/ |
| 219 | +function EnableNfcAdapter() |
| 220 | +{ |
| 221 | + EB.EzNFC.enableAdapter(); |
| 222 | +} |
| 223 | +/* |
| 224 | +enableRead(enableNfcCallback1) |
| 225 | +Method to enable NFC Tag Reading. |
| 226 | +*/ |
| 227 | +function EnableNfcRead() |
| 228 | +{ |
| 229 | + EB.EzNFC.enableRead(enableNfcCallback1); |
| 230 | +} |
| 231 | +/* |
| 232 | +disableRead(); |
| 233 | +Method to disable NFC Tag Reading. |
| 234 | +*/ |
| 235 | +function DisableNfcRead() |
| 236 | +{ |
| 237 | + EB.EzNFC.disableRead(); |
| 238 | + /* Clearing the div of previously read data*/ |
| 239 | + document.getElementById("demo5").innerHTML = ""; |
| 240 | +} |
| 241 | +/* |
| 242 | +enableRead(enableNfcCallback1). |
| 243 | +User-defined callback with the enableRead() method. |
| 244 | +Gets fired when NFC Tag is Read. |
| 245 | +Returns Tag |
| 246 | +ID |
| 247 | +Type |
| 248 | +TNF |
| 249 | +Payload |
| 250 | +EncodingFormat |
| 251 | +Result |
| 252 | +*/ |
| 253 | +function enableNfcCallback1(dat) { |
| 254 | + var ID = dat.id; |
| 255 | + var Type = dat.type; |
| 256 | + var TNF = dat.tnf; |
| 257 | + var Payload = dat.payload; |
| 258 | + var EncodingFormat = dat.encodingformat; |
| 259 | + var Result = dat.result; |
| 260 | + var TagIDHexa = dat.tagidhexa; |
| 261 | + var ShowData = "ID:" + ID + "<BR>Type:" + Type + "<BR>TNF:" + TNF + "<BR>Payload:" + Payload + "<BR>EncodingFormat:" + EncodingFormat + "<BR>Result:" + Result + "<BR>TagIDHexa: " + TagIDHexa ; |
| 262 | + |
| 263 | + document.getElementById("demo5").innerHTML = ShowData; |
| 264 | +} |
| 265 | +</script> |
| 266 | +</head> |
| 267 | +<body> |
| 268 | +<h2 align="center">Enterprise Browser NFC API Test</h2> |
| 269 | +<hr> |
| 270 | +<br> |
| 271 | +<DIV> |
| 272 | +<table border=1> |
| 273 | + <tr> |
| 274 | + <td> |
| 275 | + <button onclick="isNfcSupported();">isSupported</button>: |
| 276 | + </td> |
| 277 | + <td><div id="demo1"></div></td> |
| 278 | + </tr> |
| 279 | + <tr> |
| 280 | + <td> |
| 281 | + <button onclick="isNfcEnabled();">isEnabled</button>: |
| 282 | + </td> |
| 283 | + <td><div id="demo2"></div></td> |
| 284 | + </tr> |
| 285 | + <tr> |
| 286 | + <td colspan=2> |
| 287 | + <button onclick="EnableNfcAdapter();">enableAdapter</button>: |
| 288 | + </td> |
| 289 | + </tr> |
| 290 | + <tr> |
| 291 | + <td colspan=2> |
| 292 | + <button onclick="EnableNfcRead();">enableRead</button>:</td> |
| 293 | + </td> |
| 294 | + </tr> |
| 295 | + <tr> |
| 296 | + <td colspan=2> |
| 297 | + <button onclick="DisableNfcRead();">disableRead</button>:</td> |
| 298 | + </td> |
| 299 | + </tr> |
| 300 | +</table> |
| 301 | +</DIV> |
| 302 | +<DIV id="demo5"></DIV> |
| 303 | +</body> |
| 304 | +</html> |
| 305 | + |
| 306 | + |
| 307 | +</code></pre> |
0 commit comments