Question
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:
- Tizen NFC guide: guides/native-application/connectivity-and-wireless/nfc
- NFC manager API
- NFC tag API
Key issues I'm facing:
- The example code uses GMainLoop which isn't recognized as a valid identifier
- Should NFC event listening be started in app_resume and cleaned up in app_suspend?
- 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
Answer
Problem Understanding
The developer is trying to implement NFC tag reading functionality in a Tizen native application but encountering several technical challenges:
- Compilation issues with GMainLoop
- Uncertainty about proper NFC lifecycle management
- Difficulty interpreting error codes
- Callback registration failure
Solution Methods
-
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
-
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
-
Error Handling:
- Use
get_error_message()function to convert error codes to readable strings - Example:
const char* err_msg = get_error_message(error_code);
- Use
-
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
-
Verify NFC privileges in your tizen-manifest.xml:
<privileges> <privilege>http://tizen.org/privilege/nfc</privilege> </privileges> -
For wearable devices, note that NFC tag reading is not supported on all models (including Watch Active)
-
When debugging, check:
- Device NFC capability
- Proper privilege declaration
- Correct initialization sequence
- Error code interpretation