Send an SMS message to many recipients
This is a piece of code showing how to send an SMS to many recipients.
You can send an SMS to up to 10 recipients.
PRIVILEGES NEEDED: http://tizen.org/privilege/message.write http://tizen.org/privilege/message.read
// PRIVILEGES needed in tizen-manifest.xml:
// http://tizen.org/privilege/message.write
// http://tizen.org/privilege/message.read
#include <messages.h>
messages_service_h msg_service = NULL;
//Callback which is going to be performed when SMS sending request is processed
void on_message_sent(messages_sending_result_e result, void *user_data)
{
messages_message_h handle = (messages_message_h)user_data;
if (result == MESSAGES_SENDING_SUCCEEDED)
{
LOGI("Message sent successfully!");
}
else
{
LOGE("Sending failed!");
}
if (messages_destroy_message (handle) == MESSAGES_ERROR_NONE)
{
LOGI("Message destroyed!");
}
else
{
LOGI("Message destruction failed!");
}
}
//Opening messaging service
if (messages_open_service(&msg_service) == MESSAGES_ERROR_NONE)
{
LOGI("Messaging service opened!");
}
else
{
LOGE("Could not open messaging service!");
}
//Creating SMS with three recipients (notice calling messages_add_address() three times)
messages_message_h msg_handle = NULL;
// Instead of "+000000001"... you insert the recipient phone numbers
if (messages_create_message(MESSAGES_TYPE_SMS, &msg_handle) == MESSAGES_ERROR_NONE
&& messages_add_address(msg_handle, "+000000001", MESSAGES_RECIPIENT_TO) == MESSAGES_ERROR_NONE
&& messages_add_address(msg_handle, "+000000002", MESSAGES_RECIPIENT_TO) == MESSAGES_ERROR_NONE
&& messages_add_address(msg_handle, "+000000003", MESSAGES_RECIPIENT_TO) == MESSAGES_ERROR_NONE
&& messages_set_text(msg_handle, "Hello!")== MESSAGES_ERROR_NONE)
{
LOGI("SMS successfully created!");
}
else
{
LOGE("Error when creating SMS!");
}
//Sending SMS
if (messages_send_message(msg_service, msg_handle, true, on_message_sent, (void*)msg_handle) == MESSAGES_ERROR_NONE)
{
LOGI("Sending message requested!");
}
else
{
LOGE("Error when requested sending message!");
}
// Closing messaging service when it is not needed anymore
if (messages_close_service(msg_service) == MESSAGES_ERROR_NONE)
{
LOGI("Messaging service closed!");
msg_service = NULL;
}