Send an SMS message

This is a piece of code showing how to send an SMS. When calling messages_send_message() API the callback is set to check whether the message was successfully sent. PRIVILEGES: http://tizen.org/privilege/message.write http://tizen.org/privilege/message.read
//    PRIVILEGES needed to be set 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
messages_message_h msg_handle = NULL;

// Instead of "+000000000" you insert the recipient phone number
if (messages_create_message(MESSAGES_TYPE_SMS, &msg_handle) == MESSAGES_ERROR_NONE
    && messages_add_address(msg_handle, "+000000000", MESSAGES_RECIPIENT_TO) == MESSAGES_ERROR_NONE
    && messages_set_text(msg_handle, "Hello my friend!")== 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;
}

Responses

0 Replies