×
Namespaces

Variants
Actions
Revision as of 13:11, 10 December 2008 by dekuykin (Talk | contribs)

Removing message from Inbox in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search


Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.IMessaging.GetList(), Service.IMessaging.Delete()
Created: (24 Nov 2008)
Last edited: dekuykin (10 Dec 2008)


Overview

This code snippet shows how to delete any of inbox messages using WRT. It shows list of inbox messages (sms or mms) and allow user to delete any of them. The code snippet uses JavaScript WRT Messaging Services API. To get list of messages Service.IMessaging.GetList(criteria) method is used. criteria is the object which represents what messages we have to get. To get list of incoming messages criteria.Type = "Inbox" is used. To remove selected message Service.IMessaging.Delete(criteria) method is used with criteria.MessageId set to message id of message which is selected. To obtain access to service object for the Messaging Service API method getServiceObject("Service.Messaging", "IMessaging") is used.

Source file: RemovingMessage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>
Removing Message
</title>
<style type="text/css">
@import "removeMessage.css";
</style>
<script type="text/javascript" src="removeMessage.js"></script>
</head>
<body onLoad="setup();">
<h2>Message Remover</h2>
<table class="mainTable">
<tr>
<td>
<input type="radio" name="choiseType" checked id="sms"
onClick="getMessageList();">Sms
<input type="radio" name="choiseType" id="mms"
onClick="getMessageList();">Mms<br>
</td>
<td>
<input type="button" onClick="removeMessage();" value="Remove"><br>
</td>
</tr>
 
<tr>
<td colspan="2">
<select id="messageList" size="5" multiple>
<option disabled> </option>
</select>
</td>
</tr>
</table>
</body>
</html>

Source file: removeMessage.css

h2  {
font-weight: bold;
text-align: center;
}
input {
font-weight: bold;
}
 
.mainTable {
width: 100%;
border: groove 1px gray;
border-collapse: collapse;
background-color: white;
}
 
td {
border: solid 1px gray;
padding: 5px;
margin: 0px;
border-collapse: collapse;
text-align: center;
vertical-align: middle;
}

Source file: removeMessage.js

// removeMessage.js
 
// Object is available through a Service API. Declare service object,
// that is used to access the messaging services.
var serviceObject = null;
/**
* Java Script function.
* Closing window.
*/

function rightSoftkeyFunction() {
window.close();
}
/**
* Java Script function, used object available through a Service API.
* Initializing main controls.
*/

function setup() {
try {
document.getElementById("messageList").style.display = "none";
//Getting service object.
serviceObject = device.getServiceObject("Service.Messaging",
"IMessaging");
} catch (exception) {
alert("Service initialization error: " + exception);
return;
}
 
try {
//Setting label and handler for right softkey.
menu.setRightSoftkeyLabel("Exit", rightSoftkeyFunction);
} catch (e) {
alert("Menu initialization error: " + e);
}
 
// Get list of all messages amd show it in SELECT object.
getMessageList();
}
/**
* Java Script function.
* Viewes messages in separate list.
* @param iterator List of messages, same as result.ReturnValue
*/

function showMessages(iterator) {
var msgList = document.getElementById("messageList");
//Iterator is the list of the messages
//reset to set pointer to the first element.
iterator.reset();
var item;
 
// Clear current message list
while (msgList.length > 0) {
msgList.remove(0);
}
 
 
msgList.style.display = "block";
//Fetching values from iterator and addition it to the options.
//Value of option contains description of corresponding message.
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement ("option");
node.value = item.MessageId;
node.appendChild (document.createTextNode(item.MessageType +
item.Sender + "|" +item.Subject));
 
msgList.appendChild(node);
}
 
if (msgList.length > 0) {
msgList.options[0].selected = true;
}
 
msgList.focus();
}
/**
* Java Script function, using API from WRT 1.1 -- Messaging Service API.
* Gets list of messages.
*/

function getMessageList() {
//Setup input params using dot syntax.
var criteria = new Object();
criteria.Type = "Inbox";
criteria.Filter = new Object();
criteria.Filter.MessageTypeList = new Array();
if (document.getElementById("sms").checked == true) {
criteria.Filter.MessageTypeList[0] = "SMS";
} else {
criteria.Filter.MessageTypeList[0] = "MMS";
}
 
try {
// Get list of messages
var result = serviceObject.IMessaging.GetList(criteria);
if(result.ErrorCode != 0) {
alert("Error in getting messages");
return;
}
showMessages(result.ReturnValue);
} catch(exception) {
alert("getList: " + exception);
}
}
 
/**
* JavaScript function, uses API from WRT 1.1 - Messaging Service API.
* Removes the message which is selected in selection listbox.
*/

function removeMessage() {
// Get reference to SELECT object which containing list of messages
var msgList = document.getElementById("messageList");
// Criteria indicating the message which is required to be deleted
var criteria = new Object();
// Find messages which are selected in selection listbox
for (var msgIndex = 0; msgIndex < msgList.length; msgIndex++) {
if (msgList.options[msgIndex].selected) {
// Get message id of selected message
var messageId = msgList.options[msgIndex].value;
// Radix of message id integer value
var radix = 10;
// Get numeric representation of the message id
criteria.MessageId = parseInt(messageId, radix);
// Delete the message
var result = serviceObject.IMessaging.Delete(criteria);
if (result.ErrorCode !== 0) {
break;
}
// Remove message record from selection list
msgList.remove(msgIndex);
msgIndex = msgIndex - 1;
}
}
getMessageList();
 
}

Postconditions

After starting the snippet list of messages, "Remove" button and "SMS/MMS"checkbox are shown on display. To remove any message - user should select it in the list and choose "Remove" button. After that required message will be deleted from phone's memory and from message list. If checkbox is set to "sms" sms messages are processed; If checkbox is set to "mms" mms messages are processed.

Supplementary material

You can see source file and executable application in attached zip archive. Archive is available for download at Media:Removing_message_from_Inbox_in_WRT.zip

94 page views in the last 30 days.
×