Messages
NoteAll messages APIs have been deprecated since Tizen 8.0 and will be removed after two releases without any alternatives.
You can access the device messaging capabilities, including sending SMS and MMS messages.
The main features of the Tizen.Messaging.Messages namespace include the following:
-
Text messaging (SMS)
You can create and send SMS messages. You can also receive incoming messages, and search for messages within a message list.
-
Multimedia messaging (MMS)
You can create and send MMS messages. An image, audio, video, vCard, vCalendar, or a combination of them is supported as an attachment type in MMS messages. An image or audio attachment cannot be combined with video attachments.
-
Message notifications
You can register event handlers to be notified when an incoming message has been received.
The sent status of the SMS and MMS messages can be checked asynchronously. You receive a separate status report for each SMS recipient, and one status report for each MMS message regardless of the number of recipients.
NoteYou can test sending MMS messages on a target device only. The emulator does not support this feature.
Prerequisites
To enable your application to use the messaging functionality, follow the steps below:
-
To use the Tizen.Messaging.Messages namespace, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<privileges> <privilege>http://tizen.org/privilege/message.read</privilege> <privilege>http://tizen.org/privilege/message.write</privilege> </privileges>
-
To use the methods and properties of the
Tizen.Messaging.Messages
namespace, include it in your application:C#Copyusing Tizen.Messaging.Messages;
Manage events
To manage events related to messages, follow the steps below:
-
Define the
EventHandlerMessageReceived()
event handler, which is triggered when receiving a message:C#Copypublic static void EventHandlerMessageReceived(object sender, MessageReceivedEventArgs e) { Console.WriteLine("Text of received message: " + e.ReceivedMessage.Text); }
-
Register the event handler for the
MessageReceived
event of the Tizen.Messaging.Messages.MessagesManager class:C#CopyMessagesManager.MessageReceived += EventHandlerMessageReceived;
-
When it is no longer needed, deregister the event handler:
C#CopyMessagesManager.MessageReceived -= EventHandlerMessageReceived;
Send SMS or MMS messages
You can send SMS (Short Message Service) messages and MMS (Multimedia Message Service) messages with attachments (image or video files).
To send a message, follow the steps below:
-
Create a message by creating an instance of the Tizen.Messaging.Messages.SmsMessage or Tizen.Messaging.Messages.MmsMessage class.
The following example creates an MMS message:
C#Copyvar msg = new MmsMessage();
-
Define the recipient, as a new instance of the Tizen.Messaging.Messages.MessagesAddress class, and add the message body and SIM slot ID into the
Tizen.Messaging.Messages.MmsMessage
instance:C#Copyvar address = new MessagesAddress("1234567890"); msg.To.Add(address); msg.Text = "Tizen C# test mms message"; msg.SimId = SimSlotId.Sim1;
-
Set a subject and add an attachment for the MMS message:
-
Set a message subject:
C#Copymsg.Subject = "Tizen C# test subject";
-
Add attachments using their absolute path in the device file system. Before adding an attachment, create it as a new instance of the Tizen.Messaging.Messages.MessagesAttachment class and give it the appropriate attachment type by using values of the Tizen.Messaging.Messages.MediaType enumeration:
C#Copyvar attachment = new MessagesAttachment(MediaType.Image, "/path/to/image/file"); msg.Attachments.Add(attachment);
-
-
Send the message with the
SendMessageAsync()
method of the Tizen.Messaging.Messages.MessagesManager class:C#Copyvar result = await MessagesManager.SendMessageAsync(msg, false);
Fetch messages from a specified message box
To fetch messages from a message box, use the SearchMessageAsync()
method of the Tizen.Messaging.Messages.MessagesManager class with an appropriate filter:
-
Create a new filter as an instance of the Tizen.Messaging.Messages.MessagesSearchFilter class:
C#Copyvar filter = new MessagesSearchFilter();
-
Set filter properties.
A message filter allows you to limit your search results to a subset of all available messages based on any or all of the following:
- Message box type (inbox, outbox, sent items, drafts, or all of them)
- Message type (such as SMS or MMS)
- Keyword (for search based on text and subject)
- Address (message recipient address)
The following example shows how to define a filter that limits the search results to SMS messages in the inbox, containing “Tizen” in the text or subject and “1234” in the recipient address:
C#Copyfilter.MessageBoxType = MessageBoxType.Inbox; filter.MessageType = MessageType.Sms; filter.TextKeyword = "Tizen"; filter.AddressKeyword = "1234";
-
Perform the search:
C#Copyvar resultMessages = await MessagesManager.SearchMessageAsync(filter);
Related information
- Dependencies
- Tizen 4.0 and Higher