NFC Component

Properties   Methods   Events   Config Settings   Errors  

The NFC component is used to read and write to NFC tags.

Syntax

IPWorksNFC.NFC

Remarks

The NFC component supports tag management according to the specifications outlined in RFC 9428, in addition to RFC 4729, which defines a URN Namespace for the NFC Forum.

Project Setup

First, add the IPWorksNFC library to your Android project. Include the JAR package in your project's /libs folder or configure it via Gradle if available.

Afterwards, before the component can run successfully, the project's AndroidManifest.xml file must be configured appropriately. At minimum, the following permission and feature need to be added:

<uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc" android:required="true" />

Above, android:required may be set to false if your app doesn't require NFC to run but can take advantage of NFC when present.

Lastly, you may wish to declare certain intent filters to ensure your Activity is eligible to handle NFC-related intents, even if your Activity is not on the foreground. There are three types of NFC intents that may be applicable when scanning a tag, being ACTION_NDEF_DISCOVERED, ACTION_TECH_DISCOVERED, and ACTION_TAG_DISCOVERED. For example, the following intents may be added to the AndroidManifest.xml file:

<intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" />

For information about handling these intents in your Activity, refer to the [Foreground Dispatch System](#foreground-dispatch-system) section below. For additional information regarding NFC intents, please refer to the Android documentation here.

Initialization

To use the NFC component, you will need to import the required classes in your Activity: import ipworksnfc.*; After doing so, create the NFC component in your Activity's onCreate method and pass your Activity context to the constructor: public class MainActivity extends AppCompatActivity { private NFC m_NFC; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); m_NFC = new NFC(this); // initialize with Activity context // Add event handlers try { m_NFC.addNFCEventListener(new DefaultNFCEventListener() { public void error(NFCErrorEvent args) { } public void log(NFCLogEvent args) { } public void record(NFCRecordEvent args) { } public void tag(NFCTagEvent args) { } }); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); } } }

Foreground Dispatch System

The foreground dispatch system allows your Activity to receive NFC tag intents with priority when it is in the foreground. By enabling foreground dispatch, your app can intercept NFC intents before they are handled by other apps. The component provides three methods to integrate with this system:

To enable the foreground dispatch for your Activity, call the EnableForegroundDispatch method from the onResume callback like so: @Override protected void onResume() { super.onResume(); try { m_NFC.enableForegroundDispatch(); } catch (IPWorksNFCException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } This ensures your Activity intercepts NFC tag scans before other applications. Foreground dispatch is optional, but recommended when your Activity is actively running. Without it, Android may route tag intents to other apps. To disable the foreground dispatch for your Activity, call the DisableForegroundDispatch method from the onPause callback like so: @Override protected void onPause() { super.onPause(); try { m_NFC.disableForegroundDispatch(); } catch (IPWorksNFCException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } Disabling dispatch when the Activity is paused is critical to avoid unexpected behavior and system warnings. Lastly, when a tag is discovered, Android delivers the tag's intent to the onNewIntent callback. Forward this intent to the component using the HandleIntent method so that it can process the NFC intent (either NDEF_DISCOVERED, TECH_DISCOVERED, or TAG_DISCOVERED) like so: @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); try { m_NFC.handleIntent(intent); } catch (IPWorksNFCException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } The component filters the intent automatically, so no additional checks or filters are required here. For more information regarding the foreground dispatch system, please refer to the Android documentation here.

Reading a Tag

To read the data from a tag, call the Read method and place the tag close to the device. Please note that the Read method is blocking, and should not be called from the UI (to prevent any freezing behavior). For example:

new Thread(() -> { try { m_NFC.read(); runOnUiThread(() -> { try { Toast.makeText(this, "Read finished successfully: " + nfcManager.getTagSerialNumber(), Toast.LENGTH_SHORT).show(); } catch (IPWorksNFCException e) { Toast.makeText(this, "Read finished successfully (error reading tag serial number).", Toast.LENGTH_SHORT).show(); } dialog.dismiss(); }); } catch (IPWorksNFCException e) { runOnUiThread(() -> Toast.makeText(this, "Read error: " + e.getMessage(), Toast.LENGTH_SHORT).show()); dialog.dismiss(); } }).start();

After the tag is detected, the component will attempt to parse the tag information and any stored records. As soon as the component has read all of the tag information, the Tag event will fire, containing relevant details about the tag, such as the tag's type and serial number, current and maximum size (i.e., the amount of data the tag is currently storing or can store), and whether the tag can be written to. For example, in the Tag event:

public void tag(NFCTagEvent args) { System.out.println("Tag Detected. Details:"); System.out.println("Tag Type: " + args.forumType); System.out.println("Serial Number: " + args.serialNumber); System.out.println("Size: " + args.size + " / " + args.maxSize + " Bytes"); System.out.println("Writable: " + args.writable); }

After the Tag event fires, the Record event will fire for each record that is detected. The Record event will contain relevant details about the record, such as the record TNF (type name format, or record type format), the actual record type (which is interpreted based on the TNF), the payload (actual record content), and the optional record ID (which is typically empty). For example, in the Record event:

public void record(NFCRecordEvent args) { System.out.println("Record Detected."); System.out.println("TNF: " + args.recordTypeFormat); System.out.println("Record Type: " + args.recordType); System.out.println("Record Payload: " + args.payload); }

Note that, in addition to the tag and record details being made available via their corresponding events, the Tag property and Records collection will be populated after the Read method returns successfully. Tag and record details can also be accessed like so:

// Printing tag info public void printTagInfo() { NFCTag tag = m_NFC.getTag(); System.out.println("Tag Type: " + tag.getForumType()); System.out.println("Serial Number: " + tag.getSerialNumber()); System.out.println("Size: " + tag.getSize() + " / " + tag.getMaxSize() + " Bytes"); System.out.println("Writable: " + tag.getWritable()); } // Printing record info public void printRecordInfo() { int recordNum = 1; for (NDEFRecord record : m_NFC.getRecords()) { System.out.println("Record " + recordNum + " Info"); System.out.println("TNF: " + record.getRecordTypeFormat()); System.out.println("Record Type: " + record.getRecordType()); System.out.println("Record Payload: " + record.getPayload()); System.out.println(); recordNum++; } }

Parsing Records

As mentioned, the Record event provides the raw components of each NDEF record detected on a tag. An NDEF (NFC Data Exchange Format) record is the standard way NFC tags encode and store data. Each record contains four key parts exposed by the Record event.

Typically, the RecordTypeFormat parameter will be checked first. This parameter represents the TNF (Type Name Format) associated with the record. Possible values for this parameter are:

ValueNameDescription
0x00 Empty Empty record (padding or placeholder)
0x01 Well-Known Standard types like text (T) and URI (U)
0x02 MIME Media Type Type is a MIME type (e.g., text/plain, image/jpeg)
0x03 Absolute URI Type field contains a full URI
0x04 External Type Namespaced external types (e.g., com.example:type)
0x05 Unknown Type is not provided or known
0x06 Unchanged Used for chunked data (not common)

After checking the value of the RecordTypeFormat parameter, the RecordType parameter can then be interpreted. As an example, if the TNF of a record is 0x01 (Well-Known), the RecordType is usually a single character that identifies the type of record. This value would be "T" to indicate a text record, or "U" to indicate a URI/URL record.

In either case, the mentioned parameters can be used to then determine how to interpret the Payload parameter, which is ultimately left up to the developer. For example, given a RecordTypeFormat of 0x01 and a RecordType of "T" (Well-Known Text Record), the following code (when iterating through the collection of records) can be used to extract the relevant data out of the Payload:

try { String recordType = new String(record.getRecordType(), "UTF-8"); if (record.getRecordTypeFormat() == NDEFRecord.rtfWellKnown && recordType.equals("T")) { byte[] payload = record.getPayload(); byte status = payload[0]; boolean isUtf16 = (status & 0x80) != 0; int langCodeLen = status & 0x3F; String encoding = isUtf16 ? "UTF-16" : "UTF-8"; String languageCode = new String(payload, 1, langCodeLen, "US-ASCII"); String text = new String(payload, 1 + langCodeLen, payload.length - 1 - langCodeLen, encoding); System.out.println("Text Record (" + languageCode + "): " + text); } } catch (Exception e) { // Handle exception }

The format of a text record is defined and standardized, so the payload can be parsed in a predictable way (status byte, language code, then the actual text). Other record types follow similar conventions. For example:

  • For a URI record (TNF = 0x01, RecordType = "U"), the first byte of the payload is the URI prefix code (e.g., 0x01 for "http://www.), followed by the rest of the URI string in UTF-8.
  • For a MIME Media record (TNF = 0x02), the record type is a MIME type (e.g., "text/plain"), and the payload contains raw data of that type.

In practice, this means that the RecordTypeFormat (TNF) tells you how to interpret the RecordType, which in turn tells you how to parse the Payload. By combining these, you can effectively parse any NDEF record type.

Writing to a Tag

To write records to a tag, the Records collection should first be populated with any records that are to be written to the tag. To do so, the API exposes three methods:

The AddTextRecord method can be used to add a well-formed text record to the Records collection. This is typically used to encode human-readable text. This method takes two parameters: the actual text to store on the tag, and the language code that specifies the language of the text (for example, "en" for English).

The AddURLRecord method can be used to add a URI or URL record to the Records collection. This method takes a single parameter, which is the URL string to store on the tag.

For all other types of records, including custom or MIME-based records, the AddRecord method may be used. This method requires specifying the TNF (Type Name Format), the record type, an optional record ID, and the record payload.

As there are many possible types of records, this method is intended to give developers full control over record creation. While AddTextRecord and AddURLRecord cover some common scenarios, AddRecord allows developers to handle any custom, proprietary, or less common NDEF records without introducing additional specialized methods. As an example, you could create a MIME Media record like containing JSON like so:

try { int tnf = 0x02; byte[] recordType = "application/json".getBytes(Charset.forName("US-ASCII")); byte[] id = new byte[0]; // Prepare JSON JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "NFC Example"); jsonObject.put("version", "1.0"); jsonObject.put("data", "some_json_data"); byte[] payload = jsonObject.toString().getBytes(Charset.forName("UTF-8")); m_NFC.addRecord(tnf, recordType, payload, id); } catch (Exception ex) { System.out.println("Failed to add JSON MIME record: " + ex.getMessage()); }

Once the desired records are added to the Records collection, the Write method should be called to write the records to the tag. If multiple records are added, they will be written together as a single NDEF message. Please note that the Write method is blocking. To prevent the UI from freezing, the method should be called like so:

new Thread(() -> { try { m_NFC.write(); runOnUiThread(() -> { dialog.dismiss(); Toast.makeText(this, "Write finished successfully.", Toast.LENGTH_SHORT).show(); }); } catch (IPWorksNFCException e) { runOnUiThread(() -> { dialog.dismiss(); Toast.makeText(this, "Write error: " + e.getMessage(), Toast.LENGTH_SHORT).show(); }); } }).start();

Note that if you previously read a tag, the Records collection will likely be populated. Unless you are preserving the existing records from the prior read operation, you can clear the records from the collection like so:

m_NFC.getRecords().clear(); After clearing the records, you can add new records to write using the methods described previously.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

AvailableIndicates whether NFC is currently enabled and supported on the current device.
RecordsA collection of NDEF records.
TagInformation about the last nfctag detected with a Read operation.
TimeoutTimeout in seconds to wait for a tag during Read and Write operations.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

abortCancels an ongoing Read or Write operation that is waiting for a tag.
addRecordAdds a custom NDEFRecord to the Records collection.
addTextRecordAdds an NDEF Text record to the Records collection.
addURLRecordAdds an NDEF URI/URL record to the Records collection.
configSets or retrieves a configuration setting.
disableForegroundDispatchDisables Android foreground dispatch.
enableForegroundDispatchEnables Android foreground dispatch for a visible Activity.
handleIntentProcesses NFC discovery intents delivered to your Activity.
readReads a presented NFC tag.
resetResets the component to its initial state by clearing records and tag information.
writeWrites the record(s) in the Records collection to a detected NFC tag.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorFired when information is available about errors during data delivery.
LogFired once for each log message.
RecordFires once for each NDEF Record discovered during a Read operation.
TagFires once when a tag is discovered during a Read operation.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

BuildInfoInformation about the product's build.
GUIAvailableWhether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
MaskSensitiveDataWhether sensitive data is masked in log messages.
UseDaemonThreadsWhether threads created by the component are daemon threads.
UseInternalSecurityAPIWhether or not to use the system security libraries or an internal implementation.

Available Property (NFC Component)

Indicates whether NFC is currently enabled and supported on the current device.

Syntax

public boolean isAvailable();

Default Value

False

Remarks

This property indicates whether NFC is currently enabled and supported on the current device.

If false, the component will not be able to perform any read or write operations. This property may be checked before attempting to call Read or Write. Note that availability is also checked during the calls to Read and Write, and the methods will return an error if NFC is not supported on the current device.

This property is read-only.

Records Property (NFC Component)

A collection of NDEF records.

Syntax

public NDEFRecordList getRecords();

Remarks

This property holds a collection of NDEF records.

In the case of a Read operation, this property will hold a collection of NDEF records that were read on the tag (assuming Read returned successfully). Note that record information is also made available via the Record event. For example, to iterate through all detected records:

// Reading records after a successful read for (NDEFRecord record : m_NFC.getRecords()) { // Process records }

In the case of a Write operation, this property will hold records to be written to a tag. To add a record to this collection, AddTextRecord, AddURLRecord, and AddRecord can be called. Once populated, Write can be called to write all records in this collection to a tag. For example:

// Adding records for writing nfc.AddTextRecord("Hello World"); nfc.AddURLRecord("https://www.nsoftware.com"); // Check record count before writing if (nfc.RecordsCount > 0) { // Call write on another thread }

Note that if you previously read a tag, this collection will likely be populated. Unless you are preserving records from the prior read operation, you can clear the records from the collection before a write like so:

m_NFC.getRecords().clear();

Please refer to the NDEFRecord type for a complete list of fields.

Tag Property (NFC Component)

Information about the last nfctag detected with a Read operation.

Syntax

public NFCTag getTag();

Remarks

This property holds information about the last NFCTag detected with a Read operation. See NFCTag for the available fields.

For example, after reading a tag, you can access it's properties like so:

public void printTagInfo() { NFCTag tag = m_NFC.getTag(); System.out.println("Tag Type: " + tag.getForumType()); System.out.println("Serial Number: " + tag.getSerialNumber()); System.out.println("Size: " + tag.getSize() + " / " + tag.getMaxSize() + " Bytes"); System.out.println("Writable: " + tag.getWritable()); }

This property is read-only.

Please refer to the NFCTag type for a complete list of fields.

Timeout Property (NFC Component)

Timeout in seconds to wait for a tag during Read and Write operations.

Syntax

public int getTimeout();
public void setTimeout(int timeout);

Default Value

30

Remarks

Applies to blocking operations; after the timeout elapses, the call returns without a tag.

Abort Method (NFC Component)

Cancels an ongoing Read or Write operation that is waiting for a tag.

Syntax

public void abort();

Remarks

This method cancels an ongoing Read or Write operation that is waiting for a tag. It may be invoked from any context (such as a background thread on Android or a background dispatch queue on iOS) to interrupt a pending operation.

Example:

// In a background thread new Thread(() -> { try { nfc.Read(); // waits for tag } catch (Exception e) { // Handle cancellation or timeout } }).start(); // From UI thread to cancel cancelButton.setOnClickListener(v -> nfc.Abort());

AddRecord Method (NFC Component)

Adds a custom NDEFRecord to the Records collection.

Syntax

public void addRecord(int recordTypeFormat, byte[] recordType, byte[] payload, byte[] id);

Remarks

This method adds a custom NDEFRecord to the Records collection with the specified parameters.

The RecordTypeFormat is used to specify the format of the record (this is also known as the Type Name Format, or TNF). Possible values for this parameter are:

ValueNameDescription
0x00 Empty Empty record (padding or placeholder)
0x01 Well-Known Standard types like text (T) and URI (U)
0x02 MIME Media Type Type is a MIME type (e.g., text/plain, image/jpeg)
0x03 Absolute URI Type field contains a full URI
0x04 External Type Namespaced external types (e.g., com.example:type)
0x05 Unknown Type is not provided or known
0x06 Unchanged Used for chunked data (not common)

The RecordType parameter, normally assigned based on the RecordTypeFormat being specified, defines the type of the record. For example, if the RecordTypeFormat is set to MIME media (0x02), the RecordType might be "text/plain" or "application/json".

The Payload parameter contains the actual data of the record. This may be text, binary data, or any other content defined by the record type. For instance, for a text record this would contain the text string, while for a URI record it would contain the URI bytes.

The Id parameter is an optional identifier for the record. It may be specified to uniquely identify a record within an NDEF message, or left empty if not needed.

For common cases use AddTextRecord or AddURLRecord. Otherwise, use this method to add a custom record, for example:

try { int recordTypeFormat = 0x02; byte[] recordType = "application/json".getBytes(Charset.forName("US-ASCII")); byte[] id = new byte[0]; // Prepare JSON JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "NFC Example"); jsonObject.put("version", "1.0"); jsonObject.put("data", "some_json_data"); byte[] payload = jsonObject.toString().getBytes(Charset.forName("UTF-8")); m_NFC.addRecord(recordTypeFormat, recordType, payload, id); } catch (Exception ex) { System.out.println("Failed to add JSON MIME record: " + ex.getMessage()); }

AddTextRecord Method (NFC Component)

Adds an NDEF Text record to the Records collection.

Syntax

public void addTextRecord(String text, String languageCode);

Remarks

This method adds an NDEF Text record to the Records collection with the specified parameters.

The Text parameter specifies the actual text content of the record.

The LanguageCode parameter specifies the language of the text, using a standard IANA language code (for example, "en" for English or "fr" for French).

Note that at least one record must be added before calling Write.

Example:

nfc.AddTextRecord("Hello, World!", "en"); nfc.AddTextRecord("Visitez notre site web pour plus d'informations", "fr");

AddURLRecord Method (NFC Component)

Adds an NDEF URI/URL record to the Records collection.

Syntax

public void addURLRecord(String URL);

Remarks

This method adds an NDEF URI record to the Records collection with the specified parameter.

The URL parameter specifies the URI/URL to store in the record. The URL should conform to a valid URI scheme, for example "https://", "mailto:", etc.

Note that at least one record must be added before calling Write.

Example:

nfc.AddURLRecord("https://www.nsoftware.com"); nfc.AddURLRecord("mailto:info@nsoftware.com");

Config Method (NFC Component)

Sets or retrieves a configuration setting.

Syntax

public String config(String configurationString);

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

DisableForegroundDispatch Method (NFC Component)

Disables Android foreground dispatch.

Syntax

public void disableForegroundDispatch();

Remarks

Call from onPause() and pair with EnableForegroundDispatch in onResume().

Example:

@Override protected void onPause() { super.onPause(); try { nfc.DisableForegroundDispatch(); } catch (Exception e) { // Handle cleanup errors } }

EnableForegroundDispatch Method (NFC Component)

Enables Android foreground dispatch for a visible Activity.

Syntax

public void enableForegroundDispatch();

Remarks

Call from onResume() and pair with DisableForegroundDispatch in onPause().

Example:

@Override protected void onResume() { super.onResume(); try { nfc.EnableForegroundDispatch(); } catch (Exception e) { // Handle NFC setup errors } }

HandleIntent Method (NFC Component)

Processes NFC discovery intents delivered to your Activity.

Syntax

public void handleIntent(android.content.Intent intent);

Remarks

This method must be called from the Activity's onNewIntent() method to properly handle NFC Intents:

Example:

@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); try { nfc.HandleIntent(intent); } catch (Exception e) { // Handle NFC processing errors } }

Read Method (NFC Component)

Reads a presented NFC tag.

Syntax

public void read();

Remarks

This method attempts to read a presented NFC tag and blocks until either a tag is detected or the operation times out.

The Timeout property specifies the maximum time, in seconds, to wait for a tag before returning. If no tag is detected within the specified timeout, the method will return without reading.

The method may throw an exception if the operation is cancelled (for example, by calling Abort) or if another error occurs.

After a tag is successfully detected, the Tag and Record events will fire, containing details about the tag and records present on the tag, respectively. Additionally, the Tag property and Records collection will be populated with this same information. Please refer to the relevent event and property descriptions for additional details.

Example:

// In a background thread new Thread(() -> { try { nfc.Read(); // waits for tag or timeout } catch (Exception e) { // Handle cancellation or timeout } }).start();

Reset Method (NFC Component)

Resets the component to its initial state by clearing records and tag information.

Syntax

public void reset();

Remarks

Does not affect the Activity reference or foreground dispatch. Use Abort if there is a need to interrupt an ongoing Read or Write operation.

Example:

// After completing an operation nfc.Write(); // Write some records nfc.Reset(); // Clear everything for next operation nfc.AddTextRecord("New message"); nfc.Write(); // Write new records

Write Method (NFC Component)

Writes the record(s) in the Records collection to a detected NFC tag.

Syntax

public void write();

Remarks

This method will attempt to write the record(s) in the Records collection to a detected NFC tag.

The Timeout property specifies the maximum time, in seconds, to wait for a tag before returning. If no tag is detected within the specified timeout, the method will return without writing.

The method may throw an exception if the operation is cancelled (for example, by calling Abort) or if another error occurs.

Before calling this method, at least one record must be added to Records (for example, using AddTextRecord, AddURLRecord, or AddRecord). After a successful write, the tag will contain the records from the Records collection.

Example:

// In a background thread new Thread(() -> { try { // Add one or more records nfc.AddTextRecord("Hello, World!", "en"); nfc.Write(); // waits for tag and writes } catch (Exception e) { // Handle cancellation or timeout } }).start();

Error Event (NFC Component)

Fired when information is available about errors during data delivery.

Syntax

public class DefaultNFCEventListener implements NFCEventListener {
  ...
  public void error(NFCErrorEvent e) {}
  ...
}

public class NFCErrorEvent {
  public int errorCode;

  public String description;

}

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

The ErrorCode parameter contains an error code, and the Description parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Log Event (NFC Component)

Fired once for each log message.

Syntax

public class DefaultNFCEventListener implements NFCEventListener {
  ...
  public void log(NFCLogEvent e) {}
  ...
}

public class NFCLogEvent {
  public int logLevel;

  public String message;

  public String logType;

}

Remarks

This event is fired once for each log message generated by the component. The verbosity is controlled by the LogLevel setting.

LogLevel indicates the level of message. Possible values are as follows:

0 (None) No events are logged.
1 (Info - default) Informational events are logged.
2 (Verbose) Detailed data are logged.
3 (Debug) Debug data are logged.

The value 1 (Info) logs basic information, including the URL, HTTP version, and status details.

The value 2 (Verbose) logs additional information about the request and response.

The value 3 (Debug) logs the headers and body for both the request and response, as well as additional debug information (if any).

Message is the log entry.

LogType identifies the type of log entry. Possible values are as follows:

  • "Info"
  • "RequestHeaders"
  • "ResponseHeaders"
  • "RequestBody"
  • "ResponseBody"
  • "ProxyRequest"
  • "ProxyResponse"
  • "FirewallRequest"
  • "FirewallResponse"

Record Event (NFC Component)

Fires once for each NDEF Record discovered during a Read operation.

Syntax

public class DefaultNFCEventListener implements NFCEventListener {
  ...
  public void record(NFCRecordEvent e) {}
  ...
}

public class NFCRecordEvent {
  public byte[] id;

  public byte[] payload;

  public byte[] recordType;

  public int recordTypeFormat;

}

Remarks

This event is triggered for each NDEF record detected on the tag. The event provides access to the following parameters:

The Id parameter is the identifier of the record, if one was specified when the record was created. This may be used to uniquely distinguish records within an NDEF message. This parameter is typically empty, as it is optional.

The Payload parameter contains the actual data stored in the record. This may be text, binary data, or any other content, depending on the record type.

The RecordType parameter specifies the type of the record, usually based on the RecordTypeFormat. For example, with a MIME media format (0x02), the RecordType might be "text/plain" or "application/json".

The RecordTypeFormat parameter specifies the Type Name Format (TNF) of the record. Possible values for this parameter are:

ValueNameDescription
0x00 Empty Empty record (padding or placeholder)
0x01 Well-Known Standard types like text (T) and URI (U)
0x02 MIME Media Type Type is a MIME type (e.g., text/plain, image/jpeg)
0x03 Absolute URI Type field contains a full URI
0x04 External Type Namespaced external types (e.g., com.example:type)
0x05 Unknown Type is not provided or known
0x06 Unchanged Used for chunked data (not common)

This event will fire once for each record present on the tag. For example, if a tag contains multiple text or URI records, the event will be raised separately for each record. In addition to this event, the record data will be present in the Records collection after the Read operation is successful.

Example:

public void record(NFCRecordEvent args) { System.out.println("Record Detected."); System.out.println("TNF: " + args.recordTypeFormat); System.out.println("Record Type: " + args.recordType); System.out.println("Record Payload: " + args.payload); }

Tag Event (NFC Component)

Fires once when a tag is discovered during a Read operation.

Syntax

public class DefaultNFCEventListener implements NFCEventListener {
  ...
  public void tag(NFCTagEvent e) {}
  ...
}

public class NFCTagEvent {
  public int forumType;

  public int maxSize;

  public String serialNumber;

  public int size;

  public boolean writable;

}

Remarks

This event is triggered when a tag is successfully detected. The event provides access to the following parameters:

The ForumType parameter specifies the type of the tag according to the NFC Forum specification.

The MaxSize parameter indicates the maximum storage size of the tag, in bytes.

The SerialNumber parameter contains the unique serial number of the tag as a string. This may be empty or unavailable on some tags.

The Size parameter specifies the current amount of used storage on the tag, in bytes.

The Writable parameter indicates whether the tag is currently writable (true) or read-only (false).

In addition to this event, the tag information will be available in the Tag property after a successful Read operation.

Example:

public void tag(NFCTagEvent args) { System.out.println("Tag Detected. Details:"); System.out.println("Tag Type: " + args.forumType); System.out.println("Serial Number: " + args.serialNumber); System.out.println("Size: " + args.size + " / " + args.maxSize + " Bytes"); System.out.println("Writable: " + args.writable); }

NDEFRecord Type

The NDEFRecord type represents a single NDEF Record.

Remarks

Each record consists of a type identifier, payload data, optional ID, and format information.

The following fields are available:

Fields

Id
String

Default Value: ""

This optional field is for differentiating between multiple records in one message.

IdB
byte []

Default Value: ""

This optional field is for differentiating between multiple records in one message.

Payload
String

Default Value: ""

The Payload field contains the record's data.

This field is interpreted according to the record type (e.g., Text, URI, MIME, or custom application formats).

PayloadB
byte []

Default Value: ""

The Payload field contains the record's data.

This field is interpreted according to the record type (e.g., Text, URI, MIME, or custom application formats).

RecordType
String

Default Value: ""

The RecordType field defines the type of data contained in the record's Payload.

This field defines the type of data contained in the Payload field. The interpretation of this field depends on the RecordTypeFormat (TNF) value.

RecordTypeB
byte []

Default Value: ""

The RecordType field defines the type of data contained in the record's Payload.

This field defines the type of data contained in the Payload field. The interpretation of this field depends on the RecordTypeFormat (TNF) value.

RecordTypeFormat
int

Default Value: 0

The RecordTypeFormat field determines how the RecordType is interpreted.

The following values are acceptable:

rtfEmpty Empty NDEF Record with no type, ID, or payload.
rtfWellKnown The record type follows the NFC Forum well-known type format.
rtfMIMEMedia The record type is a MIME media type as defined by RFC 2046.
rtfAbsoluteURI The record type is an absolute URI as defined by RFC 3986.
rtfExternalType The record type follows the NFC Forum external type format.
rtfUnknown The record type format is unknown or unsupported.
rtfUnchanged The record type format remains unchanged.
rtfReserved Reserved for future use by the NFC Forum.

NFCTag Type

This type an represents an NFCTag with its properties and capabilities.

Remarks

The following fields are available:

Fields

ForumType
int

Default Value: 0

The ForumType field represents the NFC Forum tag type classification of the detected tag.

This value is automatically determined during a Read operation.

MaxSize
int

Default Value: 0

The maximum storage capacity of the NFCTag in bytes.

This read-only field indicates the total amount of data that can be stored on the NFC tag.

SerialNumber
String

Default Value: ""

The unique identifier of the NFCTag.

This field contains the hexadecimal string representation of the tag's unique identifier (UID). It is determined during an Read operation, and it cannot be modified.

Size
int

Default Value: 0

The current amount of data stored on the NFCTag in bytes.

This read-only field indicates how much of the tag's storage capacity is currently being used by NDEF message data.

Writable
boolean

Default Value: False

True if the detected tag supports write operations. False if it is read-only or write-protected.

This field is populated during a read operation and reflects the state of the tag.

Config Settings (NFC Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the component does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitiveData:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

UseDaemonThreads:   Whether threads created by the component are daemon threads.

If set to True (default), when the component creates a thread, the thread's Daemon property will be explicitly set to True. When set to False, the component will not set the Daemon property on the created thread. The default value is True.

UseInternalSecurityAPI:   Whether or not to use the system security libraries or an internal implementation.

When set to false, the component will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this configuration setting to true tells the component to use the internal implementation instead of using the system security libraries.

This setting is set to false by default on all platforms.

Trappable Errors (NFC Component)