Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Showing message information notifications in Symbian Web Runtime

From Wiki
Jump to: navigation, search

This code example shows how to register your application to receive notifications on sent messages on Symbian Web Runtime.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.IMessaging.RegisterNotification(),
Created: ivruban (10 Dec 2008)
Last edited: hamishwillee (05 Oct 2012)

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.

See also

This page was last modified on 5 October 2012, at 06:56.
64 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×