Implementing NFC Tag Reading in Tizen Native Application

Original Created Apr 14, 2020 | Regeneration Apr 22, 2026

I'm developing a native Tizen application that needs to read NFC tag content. The app currently has basic functionality with a list and REST calls to a server. I want to add NFC tag reading capability when the app is active on screen.

I'm following these references:

  1. Tizen NFC guide: guides/native-application/connectivity-and-wireless/nfc
  2. NFC manager API
  3. NFC tag API

Key issues I'm facing:

  1. The example code uses GMainLoop which isn't recognized as a valid identifier
  2. Should NFC event listening be started in app_resume and cleaned up in app_suspend?
  3. How to print meaningful error messages when errors are enums?

Current implementation:

  • NFC initialization and callback setup
  • Tag discovery handling
  • App lifecycle management for NFC

Error encountered:

  • NFC is supported on the device
  • But getting error -1073741822 when trying to register tag discovery callback

Problem Understanding

The developer is trying to implement NFC tag reading functionality in a Tizen native application but encountering several technical challenges:

  1. Compilation issues with GMainLoop
  2. Uncertainty about proper NFC lifecycle management
  3. Difficulty interpreting error codes
  4. Callback registration failure

Solution Methods

  1. GMainLoop Issue:

    • The GMainLoop is part of GLib and requires proper header inclusion
    • Add #include <glib.h> at the top of your source file
    • Link against glib library in your project configuration
  2. NFC Lifecycle Management:

    • Yes, NFC operations should be started in app_resume and stopped in app_suspend
    • This ensures NFC is only active when the app is in foreground
  3. Error Handling:

    • Use get_error_message() function to convert error codes to readable strings
    • Example: const char* err_msg = get_error_message(error_code);
  4. Callback Registration:

    • Ensure NFC is properly initialized before setting callbacks
    • Verify device NFC capability and permissions
    • Check for proper privilege declaration in manifest file

Code Examples

// Proper error handling example
if (NFC_ERROR_NONE != error_code) {
    const char* err_msg = get_error_message(error_code);
    dlog_print(DLOG_ERROR, LOG_TAG, "NFC error: %s", err_msg);
    return;
}

// Proper GLib initialization
GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
if (!mainloop) {
    dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create main loop");
    return;
}

Additional Tips

  1. Verify NFC privileges in your tizen-manifest.xml:

    <privileges>
      <privilege>http://tizen.org/privilege/nfc</privilege>
    </privileges>
    
  2. For wearable devices, note that NFC tag reading is not supported on all models (including Watch Active)

  3. When debugging, check:

    • Device NFC capability
    • Proper privilege declaration
    • Correct initialization sequence
    • Error code interpretation

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.