Accessing messages and using messaging services

The Messaging Service API allows widgets to send, retrieve, and manage messages using the Messaging Center of a device. You can use the Messaging Service to create widgets that:

  • Send SMS and MMS messages

  • Retrieve messages stored on the device

  • Notify the user when new messages arrive

  • Change the status of a message

  • Delete messages

Accessing the API and supported methods

To create a service object for the Messaging Service API, use Service.Messaging to identify the service provider and IMessaging to identify the supported interface:

var so = device.getServiceObject("Service.Messasing", "IMessaging");

The IMessaging interface provides the following methods:

  • GetList()

    Use the GetList() method to retrieve messages stored in the Messaging Center of a device.

  • Send()

    Use the Send() method to send an SMS or MMS message.

  • RegisterNotification()

    Use the RegisterNotification() method to receive notifications of new incoming messages.

  • CancelNotification()

    Use the CancelNotification() method to cancel notification of new incoming messages.

  • ChangeStatus()

    Use the ChangeStatus() method to change the read status of a message.

  • Delete()

    Use the Delete() method to delete a message.

  • Cancel()

    Use the Cancel() method to cancel an ongoing asynchronous call. This method is valid for any asynchronous call made through the Messaging Service API.

Using the service in a widget

To perform messaging tasks using the Messaging Service API:

  1. Create a service object for the API using device.getServiceObject().

  2. Define the messaging tasks you want to perform and choose the correct methods for them.

  3. Optionally, define how you want the results filtered.

  4. Define methods to process the results.

  5. Use the methods defined in step 2 to perform the messaging tasks. Use asynchronous methods together with callback().

  6. Process the results in the methods defined in step 4.

For the complete source of a sample widget that demonstrates how to use this service, see the full example.