ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / NFC functions
  • Operating mode
  • Required permissions
  • Application in the background: Specific case from Android 10
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Starts writing data to an NFC tag.
Remark: The NFC functions cannot be used in the simulator or in the emulator.
Example
// Write URL to NFC tag (blocking mode)
tag is nfcTag
url is nfcData
url.Type = nfcURI
url.Content = "http://www.pcsoft.com"
Add(tag.Data, url)
NFCWriteTag(tag)
IF ErrorOccurred THEN
Error("Unable to write NFC tag.", ErrorInfo())
END
// Write URL to NFC tag (non-blocking mode)
tag is nfcTag
url is nfcData
url.Type = nfcURI
url.Content = "http://www.pcsoft.com"
Add(tag.Data, url)
IF NOT NFCWriteTag(tag, WriteNFCTag) THEN
Error("Unable to write NFC tag.", ErrorInfo())
END
INTERNAL PROCEDURE WriteNFCTag(nNFCResult is int)
IF nNFCResult <> nfcOK THEN
Trace("A problem occurred")
END
END
Syntax

Writing a tag in blocking mode Hide the details

<Result> = NFCWriteTag(<Tag>)
<Result>: Integer
  • 1 if the writing was successful,
  • otherwise, one of the following constants:
    nfcErrDetectionThe NFC tag has exited from the detection control during the write process.
    nfcErrDisabledNFC is not enabled on the device.
    nfcErrEmulatorFunction called from the emulator.
    nfcErrFormatThe format of the data to write is invalid.
    nfcErrMaxSizeThe size of the data to write exceeds the maximum size of data that can be stored on the NFC tag.
    nfcErrNDEFThe NFC tag cannot be formatted to the NDEF format (NFC Data Exchange Format).
    nfcErrProtectionThe NFC tag cannot be protected in write mode (mode not supported by the tag).
    nfcErrReadOnlyThe NFC tag is protected in write mode.
    nfcErrUnknownUnknown error.

    If an error occurs, the ErrorOccurred variable is set to True. To get more details on the error, use ErrorInfo.
<Tag>: nfcTag variable
Name of the nfcTag variable describing the data to write.

Writing a tag in non-blocking mode Hide the details

<Result> = NFCWriteTag(<Tag> , <WLanguage procedure>)
<Result>: Boolean
  • True if the writing was started,
  • False otherwise.
<Tag>: nfcTag variable
Name of the nfcTag variable describing the data to write.
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback") called when writing data to the tag. This procedure is used to determine whether or not the data could be written to the tag. This procedure has the following format:
PROCEDURE <Procedure name>(<Result>)
where <Result> is the result of the writing operation:
  • 1 if data was successfully written to the tag,
  • otherwise, one of the following constants:
    nfcErrCancellationThe action was canceled by the user.
    nfcErrDetectionThe NFC tag has exited from the detection control during the write process.
    nfcErrDisabledNFC is not enabled on the device.
    nfcErrEmulatorFunction called from the emulator.
    nfcErrFormatThe format of the data to write is invalid.
    nfcErrMaxSizeThe size of the data to write exceeds the maximum size of data that can be stored on the NFC tag.
    nfcErrNDEFThe NFC tag cannot be formatted to the NDEF format (NFC Data Exchange Format).
    nfcErrProtectionThe NFC tag cannot be protected in write mode (mode not supported by the tag).
    nfcErrReadOnlyThe NFC tag is protected in write mode.
    nfcErrUnavailableThe NFC sensor does not exist or is not available.
    nfcErrUnknownUnknown error.
    nfcOKThe operation was completed.
Remarks

Operating mode

The call to NFCWriteTag automatically opens a window to prompt users to hold their devices closer to the NFC tag to which they want to write.
This window will be automatically closed:
  • at the end of the write operation,
  • if the user cancels the operation by pressing the Back key of the device.
Remark: To customize the message displayed in this window, use NextTitle before the call to NFCWriteTag.
A vibration is triggered when the device detects the NFC tag. The device must be located near the NFC tag during the entire display of the capture window otherwise the write process will be interrupted.

Required permissions

The call to this function modifies the permissions required by the application.
Required permissions:
  • NFC: Allows the applications to perform input/output operations via the NFC technology.
  • VIBRATE: Used to access the sensor feature.
Android

Application in the background: Specific case from Android 10

From Android 10, it is no longer possible to open a window when the application is in the background.
NFCWriteTag can open a window. If this function is used while the application is in the background, a fatal error will occur.
Tips:
  • It is possible to determine if the application is in the background using InBackgroundMode.
  • If an application needs to interact with the user while it is in the background, the solution is to display a notification (via the Notification type). The application will be brought back to the foreground when the notification is clicked, if the ActivateApplication property is set to True. You can also open a window from the procedure passed to the ActionClick property.
Related Examples:
WM System Cross-platform examples (WINDEV Mobile): WM System
[ + ] This application is an example of some of the features of WINDEV Mobile available for Android/iOS.
The following system functions are used:
- NFC
- Multimedia control
- Brightness
- Volume
- Wi-Fi
- Bluetooth
- Toast
- Compass
- Accelerometer
- Camera control
- LED
- Vibration
- Notifications
- Drawing functions
- Internet
Business / UI classification: Business Logic
Component: wd290android.aar
Minimum version required
  • Version 18
Comments
Click [Add] to post a comment

Last update: 06/22/2023

Send a report | Local help