Retrieving All SMS Messages in Tizen Native App Using messages_foreach_message API

Original Created Jul 25, 2017 | Regeneration Apr 22, 2026

I'm developing a Tizen native application that needs to access SMS messages. I'm using the Message API and specifically trying to retrieve all messages from the inbox using messages_foreach_message().

According to the Tizen documentation, this API should fetch all SMS messages in the inbox. However, in my implementation, it only retrieves the last received SMS. Here's my current code:

void messages_search_callback(messages_message_h msg, int index, int result_count, int total_count, void *user_data)
{
    dlog_print(DLOG_INFO, "inside message search callback");
}

int ret = messages_foreach_message(Message_service_handler msh, MESSAGES_MBOX_INBOX, 
    MESSAGES_TYPE_SMS, NULL, NULL, 0, 0, messages_search_callback, NULL);

Could someone help me understand:

  1. What should be the proper implementation of the callback function to iterate through all SMS messages?
  2. Why is it only retrieving the last message instead of all messages?

Problem Understanding

The issue occurs when trying to retrieve all SMS messages from the inbox using messages_foreach_message(). The callback function is being called, but only for the last message instead of all messages in the inbox.

Solution Methods

  1. Complete Callback Implementation: The callback function needs proper implementation to handle each message. Currently, it only logs a message without processing the actual message content.

  2. Message Storage: You need to store the messages as they are received in the callback. The callback is called for each message, so you should maintain a data structure to collect them.

  3. Reference Sample Code: Review the SMS sample application in Tizen Studio for a complete implementation example.

Code Examples

Here's an improved implementation of the callback function:

// Define a structure to store message data
typedef struct {
    messages_message_h *messages;
    int count;
} message_data;

void messages_search_callback(messages_message_h msg, int index, int result_count, int total_count, void *user_data)
{
    message_data *data = (message_data *)user_data;
    
    // Resize the array to accommodate new message
    data->messages = realloc(data->messages, (data->count + 1) * sizeof(messages_message_h));
    
    // Store the message handle
    data->messages[data->count] = msg;
    data->count++;
    
    dlog_print(DLOG_INFO, "Processed message %d of %d", index + 1, total_count);
}

// Usage example
message_data inbox_messages = {NULL, 0};
int ret = messages_foreach_message(msh, MESSAGES_MBOX_INBOX, MESSAGES_TYPE_SMS, 
    NULL, NULL, 0, 0, messages_search_callback, &inbox_messages);

Additional Tips

  1. The SMS sample application in Tizen Studio (located in the Sample App List) provides a complete implementation reference.
  2. Remember to free allocated memory when you're done processing the messages.
  3. Check error codes returned by messages_foreach_message() to ensure proper operation.
  4. For the latest documentation, refer to the Samsung Tizen OS website (samsungtizenos.com) as the developer.tizen.org content has been migrated there.

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.