From cc7e57b639876b2e59242f799f215db20ac47b18 Mon Sep 17 00:00:00 2001
From: Lukasz Foniok Deprecated.
+ Deprecated.
Deprecated since 2.3. Instead, let the user turn NFC on/off through the Settings application. See the Managing NFC Tutorial.
-
void setPowered(boolean state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
@@ -1879,7 +1879,15 @@ The ErrorCallback is launched with these error types:
console.log("Sending APDU reponse failed.");
};
- var apdu_response= [0x00,0xA4,0x04,0x00,0x04,0x11,0x12, 0x13, 0x14]; //set apdu response.
+ var classOfInstruction = 0x00; // No SM or no SM indication
+ var instructionCode = 0xA4; //Select File
+ var firstParam = 0x04; //Direct selection by DF name
+ var secondParam = 0x00; // First record
+ var dataFieldLength = 0x03; // Variable length 1 or 3 bytes
+ var bytes = [ 0x20, 0x21, 0x22]; // Variable length equal to dataFieldLength
+ var maxBytesExpected = 0x02; // Maximum bytes in answer
+
+ var apdu_response= [ classOfInstruction, instructionCode, firstParam, secondParam] + bytes + [ maxBytesExpected ]; //set apdu response.
adapter.sendHostAPDUResponse(apdu_response, successCB, errorCB) ;
} catch (err) {
console.log(err.name + ": " + err.message);
@@ -2246,6 +2254,29 @@ The ErrorCallback is launched with these error types:
+ Code example: Code example: Code example: Code example: Code example: try {
+
+ var successCB = function(aids) {
+ var arrayLength = aids.length;
+ for (var i = 0; i arrayLength; i++) {
+ console.log("Get AID category was successful.");
+ console.log("AID type is " + aids[i].type);
+ console.log("AID is " + aids[i].aid);
+ console.log("AID isReadOnly is " + aids[i].readOnly);
+ }
+ };
+
+ var errorCB = function() {
+ console.log("Get AID category failed.");
+ };
+
+ adapter.getAIDsForCategory("HCE", "PAYMENT", successCB, errorCB) ;
+ } catch (err) {
+ console.log(err.name + ": " + err.message);
+ }
+
+ try {
+
+ var successCB = function(ndefMessage) {
+ console.log("Message read was successful.");
+ for( var i = 0; i ndefMessage.recordCount; ++i){
+ console.log("Message record " + i + "tnf: " + ndefMessage.records[i].tnf);
+ console.log("Message record " + i + "tnf: " + ndefMessage.records[i].tnf);
+ console.log("Message record type " + ndefMessage.records[i].type.toString());
+ ...
+ }
+ };
+
+ var errorCB = function() {
+ console.log("Message read failed.");
+ };
+
+ nfcTag.readNDEF(successCB, errorCB) ;
+ } catch (err) {
+ console.log(err.name + ": " + err.message);
+ }
+
+writeNDEF
@@ -2491,6 +2545,28 @@ is not compatible with the expected type for that parameter.
+ try {
+
+ var successCB = function() {
+ console.log("Message write was successful.");
+ }
+ };
+
+ var errorCB = function() {
+ console.log("Message write failed.");
+ };
+
+
+ var record = new tizen.NDEFRecordText("Hi!", "en-GB");
+ var message = new tizen.NDEFMessage([record]);
+
+ nfcTag.writeNDEF(message, successCB, errorCB) ;
+ } catch (err) {
+ console.log(err.name + ": " + err.message);
+ }
+
+transceive
@@ -2558,6 +2634,27 @@ is not compatible with the expected type for that parameter.
+ try {
+
+ var successCB = function(data) {
+ console.log("Message write was successful.");
+ console.log("Response is " + data.toString());
+ }
+ };
+
+ var errorCB = function() {
+ console.log("Message write failed.");
+ };
+
+ var message = [0x30, 0x00, 0x02, 0xa8]; // READ command for MIFARE tags
+
+ nfcTag.transceive(message, successCB, errorCB) ;
+ } catch (err) {
+ console.log(err.name + ": " + err.message);
+ }
+
+ try {
+
+ peerListener = {
+ onattach: function (peer) {
+ var record = new tizen.NDEFRecordText("sendNDEF-test", 'en-US');
+ var message = new tizen.NDEFMessage([record]);
+ returned = peer.sendNDEF(ndefMessage);
+ },
+ ondetach: t.step_func(function () {
+ adapter.unsetPeerListener();
+ }
+ };
+
+ adapter.setPeerListener(peerListener);
+ } catch (err) {
+ console.log(err.name + ": " + err.message);
+ }
+
+
Code example:
try { + var record = new tizen.NDEFRecordText("Hi!", "en-GB"); + var tempMessage = new tizen.NDEFMessage([record]); + var rawData = tempMessage.toByte(); + + var message = new tizen.NDEFMessage(rawData); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
-// prepare two NDEFRecords: -var myRecordURI = new tizen.NDEFRecordURI("https://www.tizen.org/"); -var myRecordTextPlain = new tizen.NDEFRecordMedia("text/plain", [116, 105, 122, 101, 110]); +Code example:
try { + + // prepare two NDEFRecords: + var myRecordURI = new tizen.NDEFRecordURI("https://www.tizen.org/"); + var myRecordTextPlain = new tizen.NDEFRecordMedia("text/plain", [116, 105, 122, 101, 110]); -// create a NDEFMessage composed of two NDEFRecords: -var myMessage = new NDEFMessage([myRecordURI, myRecordTextPlain]); -+ // create a NDEFMessage composed of two NDEFRecords: + var myMessage = new NDEFMessage([myRecordURI, myRecordTextPlain]); + } catch (err) { + console.log(err.name + ": " + err.message); + } +
Code example:
try { + var recordBytes = [217, 1, 2, 3, 202, 219, 218, 217, 240, 241]; + var record = new tizen.NDEFRecord(recordBytes); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + var type = new Array(255), + var payload = new Array(256), + var recordId = [155, 150], + var newRecord = new tizen.NDEFRecord(tizen.nfc.NFC_RECORD_TNF_UNKNOWN, type, payload, recordId); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
- var newRecord = new tizen.NDEFRecord(2, [42, 84], [1, 2, 3, 4]); -+
Code example:
// Creates a new NDEF record. + var newRecord = new tizen.NDEFRecordURI("https://www.tizen.org/"); + var payload = newRecord.payload; +
Code example:
- var newRecord = new tizen.NDEFRecordText("Tizen", "en-US", "UTF8"); -+
Code example:
var newRecord = new tizen.NDEFRecordText("Tizen", "en-US", "UTF8"); +
NDEFRecordURI(DOMString uri);
Code example:
-// Creates a new NDEF record. -var newRecord = new tizen.NDEFRecordURI("https://www.tizen.org/"); -var payload = newRecord.payload; -+
Code example:
// Creates a new NDEF record. + var newRecord = new tizen.NDEFRecordURI("https://www.tizen.org/"); + var payload = newRecord.payload; +
Code example:
-var myData = [116, 105, 122, 101, 110]; -var newRecord = new tizen.NDEFRecordMedia("text/plain", myData); -+
Code example:
var myData = [116, 105, 122, 101, 110]; + var newRecord = new tizen.NDEFRecordMedia("text/plain", myData); +
Remark : + Example of using can be find at setListener code example. +
Remark : + Example of using can be find at setListener code example. +
Code example:
try { + var onSuccessCB = { + onattach: function (nfcTag){ + console.log("Successfully detected nfcTag type:" + nfcTag.type); + } + } + + var adapter = tizen.nfc.getDefaultAdapter(); + adapter.setTagListener(onSuccessCB); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
ondetach
@@ -3338,6 +3509,25 @@ It is used in NFCAdapter.setTagListener().
Since:
1.0
+Code example:
try { + var adapter; + var onSuccessCB = { + onattach: function (nfcTag){ + console.log("Successfully detected nfcTag type:" + nfcTag.type); + }, + ondetach: function() { + adapter.unsetTagListener(); + } + } + + adapter = tizen.nfc.getDefaultAdapter(); + adapter.setTagListener(onSuccessCB); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + var adapter; + var onSuccessCB = { + onattach: function (nfcPeer){ + console.log("Successfully detected nfcPeer :" + nfcPeer.isConnected); + } + } + + adapter = tizen.nfc.getDefaultAdapter(); + adapter.setPeerListener(onSuccessCB); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
ondetach
@@ -3408,6 +3614,25 @@ It is used in NFCAdapter.setPeerListener().
Since:
1.0
+Code example:
try { + var adapter; + var onSuccessCB = { + onattach: function (nfcPeer){ + console.log("Successfully detected nfcPeer :" + nfcPeer.isConnected); + }, + ondetach: function() { + adapter.unsetPeerListener(); + } + } + + adapter = tizen.nfc.getDefaultAdapter(); + adapter.setPeerListener(onSuccessCB); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + var adapter; + + var readCallback = function (ndefMessage) { + console.log("NDEFMessageReadCallback called successfully"); + } + + var tagListener = { + onattach: function (nfcTag){ + var result = nfcTag.readNDEF(readCallback); + } + } + + adapter = tizen.nfc.getDefaultAdapter(); + adapter.setTagListener(tagListener); + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var successCB = function(data) { + console.log("ByteArraySuccessCallback called successfully."); + } + }; + + var message = [0x30, 0x00, 0x02, 0xa8]; // READ command for MIFARE tags + + nfcTag.transceive(message, successCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var onSuccessCB = function(mode) { + console.log("CardEmulationModeChangeCallback called successfully"); + }; + + var listenerId = adapter.addCardEmulationModeChangeListener(onSuccessCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var onSuccessCB = function(aid, data) { + console.log("TransactionEventCallback called successfully"); + }; + + var listenerId = adapter.addTransactionEventListener("UICC", onSuccessCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var onSuccessCB = function(seType) { + console.log("ActiveSecureElementChangeCallback called successfully"); + }; + + var listenerId = adapter.addActiveSecureElementChangeListener(onSuccessCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var onDetectedCB = function(event_data) { + console.log("HCEEventReceiveCallback called successfully"); + }; + + var listenerId = adapter.addHCEEventListener(onDetectedCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
Code example:
try { + + var successCB = function(aids) { + console.log("AIDArraySuccessCallback called successfully"); + }; + + adapter.getAIDsForCategory("HCE", "PAYMENT", successCB) ; + } catch (err) { + console.log(err.name + ": " + err.message); + } ++
module NFC { -- 2.7.4