| ID | CS001246 | Creation date | December 18, 2008 |
| Platform | S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Web Runtime (WRT) | Subcategory | Messaging |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.Messaging.GetList() |
This code snippet shows how to get a list of received messages using the Messaging Platform Service for 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 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.
<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 />
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);
}
}
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.
No related wiki articles found