Showing message information notifications in Symbian Web Runtime
This code example shows how to register your application to receive notifications on sent messages on Symbian Web Runtime.
Article Metadata
Code Example
Tested with
Compatibility
Article
Contents |
Overview
The example uses the Messaging Platform Service, 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.
Source: Relevant HTML components
<p id="status"></p>Source: JavaScript file
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";
}
}
Postconditions
The snippet shows how to register for receiving notifications on message status changing.
Supplementary material
The source file and executable application are available for download at Media:Showing messages information notifications in WRT.zip.


(no comments yet)