Namespaces
Variants
Actions
Revision as of 08:58, 5 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Listing inbox messages in Symbian Web Runtime

Jump to: navigation, search

This code snippet shows how to get a list of received messages in Symbian Web Runtime, using the Messaging Platform Service (introduced in S60 5th Edition).

Article Metadata

Code Example
Tested with
Devices(s): Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 5th Edition

Article
Keywords: device.getServiceObject(), Service.Messaging.GetList()
Created: ivruban (10 Dec 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

Overview

The device.getServiceObject("Service.Messaging", "IMessaging") method is used to obtain access to the service object for the Messaging Service API.

After setting the correct values for the criteria object (criteria.Type, criteria.Filter, and criteria.Filter.MessageTypeList), the IMessaging.GetList(criteria) method is used for getting the list of messages synchronously.

Source: Relevant HTML components

<input type="radio" name="choiceType" id="sms" checked="true" />
<label for="sms">SMS</label><br />
 
<input type="radio" name="choiceType" id="mms" />
<label for="mms">MMS</label><br />
 
<input type="button" value="Get messages"
onclick="getMessageList();" />
 
<select size="5" id="messageList" multiple></select><br />

Source: JavaScript file

var serviceObj = null;
 
window.onload = init;
 
// Initializes the widget
function init() {
try {
serviceObj = device.getServiceObject("Service.Messaging",
"IMessaging");
} catch (ex) {
alert("Service object cannot be found.");
return;
}
 
// Get the list of all messages and show it in SELECT object.
getMessageList();
}
 
function getMessageList() {
var criteria = new Object();
criteria.Type = "Inbox";
criteria.Filter = new Object();
criteria.Filter.MessageTypeList = new Array();
if (document.getElementById("sms").checked) {
criteria.Filter.MessageTypeList[0] = "SMS";
} else {
criteria.Filter.MessageTypeList[0] = "MMS";
}
 
try {
// Get list of messages
var result = serviceObj.IMessaging.GetList(criteria);
if(result.ErrorCode != 0) {
alert("Error in getting messages");
return;
}
showMessages(result.ReturnValue);
} catch(exception) {
alert("getList: " + exception);
}
}
 
// Displays available messages in a list box
function showMessages(iterator) {
var messageList = document.getElementById("messageList");
//Iterator is the list of the files, reset to set pointer to the first
//element.
iterator.reset();
//Cleaning the file list.
while (messageList.length != 0) {
messageList.remove(0);
}
document.getElementById("messageList").style.display = "block";
var item;
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement("option");
//Value of option consists of the full path.
node.value = item.MessageId;
node.appendChild (document.createTextNode(item.Sender + item.Time +
item.Subject));
messageList.appendChild(node);
}
}

Postconditions

  • After loading, a listbox with all messages from inbox (SMS or MMS) is shown.
  • The user can choose the type of message.
  • Thw list box contains the "From", "Data/Time", and message text fields.

Supplementary material

You can view the source file and executable application in the attached ZIP archive. The archive is available for download at Media:Listing inbox messages in WRT.zip.

171 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved