
The NFC object may be used to manage near-field communication operations with NFC tags on the device. With it, NFC data may be read and written to tags using expressions which will be trigged when upon contact.
Currently, this is supported on Android builds 8.1.6 and higher.
NFC.Enable()
Note:
Calling this method will allow BrightForms to receive NFC events, which will trigger the 'Action - NFC Event' expression of the foreground form when an NFC tile is in contact with the device.
IF(NFC.GetEventType() == NFC_READ)
{
IF(NFC.GetLastError() == 0)
{
edit_control1 = NFC.ReadString();
}
ELSE
{
Form.MessageBox("NFC Tag", "Could not read tag.", 0);
}
}
Note:
edit_control1 – Control which loads the tag data. Scan will return 0 is successful, otherwise an error code.
The NFC.GetEventType() method will determine if the NFC event was a read, write or unknown event with NFC Event Type constants. Will only populate fields if NFC_READ is returned.
The NFC.GetLastError() returns a code whether the last event type was successful. This will return 0 if values were successfully read from the tag, but will return other values if it wasn't. For example, if a tag hasn't been initialised, it will return the code 11814.
This code would be called after the NFC.Enable() method is called, and contained in the expression assigned to a form's "Action - NFC Event". It would then run if it's form is in the foreground when the NFC event takes place.
local.vResult = NFC.WriteAsText(local.vParam1);
Note:
Will set the value of the next NFC tile contacted to local variable vParam1. Alternatively, the WriteAsURI method may be used, which will process the value as a URI when read by other applications if necessary.
IF(NFC.GetEventType() == NFC_WRITE)
{
IF(NFC.GetLastError() == 0)
{
Form.MessageBox("NFC Tag", "NFC tag written successfully.", 0);
}
ELSE
{
Form.MessageBox("NFC Tag", "Could not write tag.", 0);
}
}
Note:
The NFC.GetEventType() will write to a tag, and return NFC_WRITE if the WriteAsText() or WriteAsURI() methods are called, and a tag is contacted.
The success or failure of the write may be determined by the NFC.GetLastError() method - in the code above, this is being assess and will display a messagebox based on the returned code.
This code would be called after the NFC.Enable() method is called, and contained in the expression assigned to a form's "Action - NFC Event". It would then run if it's form is in the foreground when the NFC event takes place.
NFC.Disable()
Note:
This expression can be attached to the Action – Close property of the form to make sure that the NFC object is closed when the form is closed.