The NFC API provides the Near Field Communication (NFC) service to enable information exchange between NFC-enabled devices (called "peers") or tags. The NFC-enabled devices can share contacts, photos, and videos, and can also act as smart cards. You can use an NFC-enabled device to communicate with NFC tags for a variety of activities, such as paying the grocery bill or downloading a coupon.
NFC provides the following advantages over short-range communication technologies, such as Bluetooth:
- Faster set-up
- Lower power consumption
- No device pairing requirements
- Reduction in unwanted interruptions
An NFC tag is a chip which can securely store personal information, such as debit card numbers or contact details. The methods of the NFCTag interface are used to access an NFC tag for reading or writing information. NFC tag types are identified using the type attribute of the NFCTagType type definition.
|Samsung Web API provides the following NFC tag types: GENERIC_TARGET, ISO14443_A, ISO14443_4A, ISO14443_3A, MIFARE_MINI, MIFARE_1K, MIFARE_4K, MIFARE_ULTRA, MIFARE_DESFIRE, ISO14443_B, ISO14443_4B, ISO14443_BPRIME, FELICA, JEWEL, ISO15693, and UNKNOWN_TARGET.|
The NFC forum defines the NFC data exchange format (NDEF) for encapsulating the data exchanged between 2 NFC-enabled devices or an NFC-enabled device and an NFC tag. An NDEF message can store data in various formats, such as text, Multipurpose Internet Mail Extension (MIME) type object, or ultra-short RagTime Document (RTD). The NFC tags use NDEF for exchanging messages.
The main features of the NFC API include:
- NFC device management
You can manage NFC connectivity by enabling or disabling the NFC service.
To use NFC, retrieve the default NFC adapter using the getDefaultAdapter() method of the NFCAdapter interface. You can enable and disable NFC using the setPowered() method.
- NFC tag and peer detection
To receive notifications when an NFC tag or peer device has been detected, the setTagListener() and setPeerListener() methods of the NFCAdapter interface register event listeners, which trigger notifications when an NFC tag or peer device is detected, respectively. You can use the NFCTagDetectCallback and NFCPeerDetectCallback interfaces to define event handlers for receiving the notifications about attaching and detaching NFC tags and peers, respectively.
- NDEF message manipulation
- NDEF data exchange
To exchange data between peers, the setReceiveNDEFListener() method of the NFCPeer interface registers an event listener, which triggers an event when an NDEF message is received from a peer.
You can use the NDEFMessageReadCallback interface to define event handlers for reading NDEF messages from tags and peer devices.
|If an application is on the background and uses the writeNDEF() or sendNDEF() method, an error callback is launched. These methods can only be used in the foreground.|
You can launch NFC applications based on the NDEF message content using the application control functionalities. For example, if the application control with the http://samsungapps.com/appcontrol/operation/nfc/wellknown operation is defined in the config.xml file and an NFC-enabled device reads an NFC tag or receives an NDEF message whose first NDEF record has a record type (tnf value) set as NFC_RECORD_TNF_WELL_KNOWN, the NFC application is launched.
NFC applications can also be launched by the transaction of the card emulation functionality. NFC devices can communicate with point of sales (POS) terminals using the card emulation functionality to, for example, make a payment. If the application control with the http://samsungapps.com/appcontrol/operation/nfc/transaction operation is defined in the config.xml file and a transaction caused by the card emulation functionality occurs, the NFC application is launched.
The following table lists the NFC operations, scheme and mime.
URL, for example:
URN, for example:
For example: U/0x03, U/0x05, U/*
For example: T/*, sp/*, */*
For example: text/x-vard, text/*, */*
For example: http://samsungapps.com/about/devices
For example: nfc:ext.samsungapps.com.ABC
* The <protocol_code> and <scheme> must be in sync. See NFCForum-TS-RTD_URI_1.0 and NCF RTD (Record Type Definition) documentation on the NFC forum.