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. Thanks for all your past and future contributions.

Revision as of 07:01, 14 June 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Listening for incoming SMS messages in WRT Widget

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N97 mini
Platform(s): S60 5th Edition
S60 5th Edition
Keywords: Service.IMessaging.RegisterNotification()
Created: vasant21 (10 Jan 2010)
Last edited: hamishwillee (14 Jun 2013)



This code snippet below demonstrates how to receive incoming message notification/contents in WRT widget using Platform Services 1.0 Messaging API.

try {
var so = device.getServiceObject("Service.Messaging", "IMessaging");
} catch(e ) {
alert("Error in getting Messaging interface \n" + e);
// Our criteria is to get new messages.
var criteria = { Type : "NewMessage" };
// Lets register the widget to receive notifications of new incoming messages.
// New messages will be notified to onMessageReceived callback function.
var ret = so.IMessaging.RegisterNotification(criteria, onMessageReceived);
if( ! ret.ErrorCode ){
alert("Registration Successfull!");
alert("Registration Failed, ErrorCode :" + ret.ErrorCode );
// Callback method that is executed when RegisterNotification has results
// or status information to return.
function onMessageReceived( transId, eventCode, result ){
// NOTE: Here we use JSON library for demo so that we can check
// the entire structure of the result in case of success or error.
alert("Message Received: \n" + JSON.stringify(result ) );

Successfully received message JSON structure

ErrorCode : 0,
ReturnValue : {
Unread : true,
Attachment : false,
Priority : "Medium",
MessageId : 1048667,
Time : "Sunday, 10 January, 2010 2:35:09 pm",
Sender : "14000",
Subject : "This is a test message",
MessageType : "SMS"

Sample Widget

Sample Widget Application can be found here : SMS

How to test

After installing the above sample widget application, keep the widget application open, go to Messaging application and send a test message to yourself, then switch back to the sample widget, once the message is received on the device, you will see the dialog appearing on the screen displaying the complete structure of the message received.

This page was last modified on 14 June 2013, at 07:01.
33 page views in the last 30 days.