Send an MMS
This is a piece of code showing how to send an MMS with a picture.
When calling messages_send_message() API you can set the callback to check whether the message was successfully sent.
PRIVILEGES NEEDED: 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 with three recipients (notice calling messages_add_address() three times)
messages_message_h msg_handle = NULL;
// Instead of "+000000000" you insert the recipient phone number
if (messages_create_message(MESSAGES_TYPE_MMS, &msg_handle) == MESSAGES_ERROR_NONE
&& messages_add_address(msg_handle, "+000000000", MESSAGES_RECIPIENT_TO) == MESSAGES_ERROR_NONE
&& messages_mms_set_subject(msg_handle, "MMS for you") == MESSAGES_ERROR_NONE
&& messages_mms_add_attachment(msg_handle, MESSAGES_MEDIA_IMAGE, "/opt/usr/media/DCIM/Camera/Photo.jpg") == MESSAGES_ERROR_NONE
&& messages_set_text(msg_handle, "Hello!")== MESSAGES_ERROR_NONE )
{
LOGI("MMS successfully created!");
}
else
{
LOGE("Error when creating MMS!");
}
// 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;
}