| ID | CS001236 | Creation date | December 18, 2008 |
| Platform | S60 5th Edition | Tested on devices | Nokia 5800XpressMusic |
| Category | Web Runtime (WRT) | Subcategory | Messaging |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.IMessaging.RegisterNotification(),
Service.IMessaging.Send() |
This code snippet shows how to register your application to receive notifications on sent messages using the Messaging Platform Service for S60 Web Runtime introduced in S60 5th Edition.
The device.getServiceObject("Service.Messaging", "IMessaging") method is used to obtain access to the service object for the Messaging Service API.
After setting up the values for the notification type (notificationCriteria.NotificationType), the IMessaging.RegisterNotification(notificationCriteria,showMessagesStatus) method is used to register for notifications. The IMessaging.RegisterNotification() method is asynchronous and uses the showMessagesStatus() as a callback function.
<p id="status"></p>
var serviceObj = null;
// Initializes the widget
function initialize() {
document.getElementById("status").style.display = "none";
// Obtain the service object
try {
serviceObj = device.getServiceObject("Service.Messaging",
"IMessaging");
} catch(exception) {
alert("Service object cannot be found.");
return;
}
}
function sendMessageAndNotify() {
// The sending part omitted. Refer to the See also section for the code
// snippet that provides you with more information about the sending.
// ...
try {
var notificationCriteria = new Object();
notificationCriteria.Type = "NewMessage";
//Registering for notification on new events.
var result = serviceObj.IMessaging.RegisterNotification(
notificationCriteria, showMessagesStatus);
} catch (exception) {
alert("Register message notification error: " + exception);
}
}
/**
* Callback function used to handle changes in the messaging status.
* @param transId This is a number representing the transaction that called
* the callback
* @param eventCode This is a number representing the callback return status.
* @param result This is an object for holding the callback return value.
*/
function showMessagesStatus(transId, eventCode, result) {
if (result.ErrorCode == 0) {
document.getElementById("status").innerHTML =
"You have a new message!";
document.getElementById("status").style.display = "block";
}
}
The snippet shows how to register for receiving notifications on message status changing.
The source file and executable application are available for download at Media:Showing_messages_information_notifications_in_WRT.zip.
No related wiki articles found