Skip to content

NFC-NFCAdapter

NFCAdapter

  • Parameters and descriptions: Object tech, Tag type enumeration
    PropertiesTypeDescription
    ndefStringCorresponding to the Ndef instance, the instance supports reading and writing NDEF data on NFC tags in NDEF format
    nfcAStringCorresponding to the NfcA instance, the instance supports reading and writing of the NFC-A (ISO 14443-3A) standard
    nfcBStringCorresponding to the NfcB instance, the instance supports reading and writing of the NFC-B (ISO 14443-3B) standard
    isoDepStringCorresponding to the IsoDep instance, the instance supports reading and writing according to the ISO-DEP (ISO 14443-4) standard
    nfcFStringCorresponding to the NfcF instance, the instance supports reading and writing of the NFC-F (JIS 6319-4) standard
    nfcVStringCorresponding to the NfcV instance, the instance supports reading and writing of the NFC-V (ISO 15693) standard
    mifareClassicStringCorresponding to the MifareClassic instance, the instance supports reading and writing MIFARE Classic tags
    mifareUltralightStringCorresponding to the MifareUltralight instance, the instance supports reading and writing MIFARE Ultralight tags

.startDiscovery

TIP

The API usage is as follows: NFCAdapter.startDiscovery()

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Error code

    Error codeError messageDescription
    13000The device does not support NFC-
    13001The system NFC switch is not turned on-
    13010Unknown error-
    13019user is not authorizedThe user is not authorized
    13011invalid parameterInvalid parameters
    13012parse NdefMessage failedFailed to parse parameters into NdefMessage
    13021NFC discovery already startedNFC scanning has started
    13018NFC discovery has not startedAttempt to stop NFC scanning when NFC scanning has not started
    13022Tech already connectedThe tag is already connected
    13023Tech has not connectedAttempt to disconnect when the tag is not connected
    13013NFC tag has not been discoveredNFC tag not scanned
    13014invalid techInvalid tag technology
    13015unavailable techFailed to obtain the corresponding technology from the tag
    13024function not supportThe current tag technology does not support this function
    13017system internal errorRelated read and write operations failed
    13016connect failConnection failed

.stopDiscovery

TIP

The API usage is as follows: NFCAdapter.stopDiscovery()

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Error code

    Error codeError messageDescription
    13000The device does not support NFC-
    13001The system NFC switch is not turned on-
    13010Unknown error-
    13019user is not authorizedThe user is not authorized
    13011invalid parameterInvalid parameters
    13012parse NdefMessage failedFailed to parse parameters into NdefMessage
    13021NFC discovery already startedNFC scanning has started
    13018NFC discovery has not startedAttempt to stop NFC scanning when NFC scanning has not started
    13022Tech already connectedThe tag is already connected
    13023Tech has not connectedAttempt to disconnect when the tag is not connected
    13013NFC tag has not been discoveredNFC tag not scanned
    13014invalid techInvalid tag technology
    13015unavailable techFailed to obtain the corresponding technology from the tag
    13024function not supportThe current tag technology does not support this function
    13017system internal errorRelated read and write operations failed
    13016connect failConnection failed

.getNdef

TIP

The API usage is as follows: Ndef NFCAdapter.getNdef()

  • Functional description: Get Ndef instances, which support reading and writing NDEF data on NFC tags in NDEF format
  • Return value: Ndef

.getNfcA

TIP

The API usage is as follows: Ndef NFCAdapter.getNfcA()

  • Functional description: Get an NfcA instance, which supports reading and writing the NFC-A (ISO 14443-3A) standard
  • Return value: NfcA

.getNfcB

TIP

The API usage is as follows: NfcB NFCAdapter.getNfcB()

  • Functional description: Get an NfcB instance, which supports reading and writing the NFC-B (ISO 14443-3B) standard
  • Return value: NfcB

.getNfcF

TIP

The API usage is as follows: NfcF NFCAdapter.getNfcF()

  • Functional description: Get an NfcF instance, which supports reading and writing the NFC-F (JIS 6319-4) standard
  • Return value: NfcF

.getNfcV

TIP

The API usage is as follows: NfcV NFCAdapter.getNfcV()

  • Functional description: Get an NfcV instance, which supports reading and writing the NFC-V (ISO 15693) standard
  • Return value: NfcV

.getIsoDep

TIP

The API usage is as follows: IsoDep NFCAdapter.getlsoDep()

  • Functional description: Get an IsoDep instance that supports reading and writing the ISO-DEP (ISO 14443-4) standard
  • Return value: IsoDep

.getMifareClassic

TIP

The API usage is as follows: MifareClassic NFCAdapter.getMifareClassic()

  • Functional description: Get the MifareClassic instance, which supports reading and writing MIFARE Classic tags
  • Return value: MifareClassic

.getMifareUltralight

TIP

The API usage is as follows: MifareUltralight NFCAdapter.getMifareUltralight()

  • Functional description: Get the MifareUltralight instance, which supports reading and writing MIFARE Ultralight tags
  • Return value: MifareUltralight

.onDiscovered

TIP

The API usage is as follows: NFCAdapter.onDiscovered(function listener)

  • Functional description: Monitor NFC Tag
  • Parameters and descriptions: function listener,Listening function, the parameter Object res is as follows:
    PropertiesTypeDescription
    idArrayBuffer-
    techsArraytech array, used to match what standard (such as NfcA) can be used for NFC card processing
    messagesArrayNdefMessage array, the message format is {id: ArrayBuffer, type: ArrayBuffer, payload: ArrayBuffer}

.offDiscovered

TIP

The API usage is as follows: NFCAdapter.offDiscovered(function listener)

  • Functional description: Remove the listening function of NFC Tag

  • Parameters and descriptions: function listener,The listening function passed in by onDiscovered. If this parameter is not passed, all listening functions will be removed

  • Sample code:

js
const listener = function (res) { console.log(res) }

NFCAdapter.onDiscovered(listener)
NFCAdapter.offDiscovered(listener) // Pass the same function object used for listening.