×
Namespaces

Variants
Actions
(Difference between revisions)

Removing message from Inbox in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
seppo_fn (Talk | contribs)
copyeditor (Talk | contribs)
m (language check)
Line 13: Line 13:
  
 
==Overview==
 
==Overview==
This code snippet shows how to delete a message from Messaging inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition.
+
This code snippet shows how to delete a message from the Messaging inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition.  It shows a list of inbox messages (sms or mms) and allows user to delete any of them.
  
It shows list of inbox messages (sms or mms) and allow user to delete any of them.
 
 
The code snippet  uses <tt>JavaScript WRT Messaging Services API</tt>.
 
The code snippet  uses <tt>JavaScript WRT Messaging Services API</tt>.
To get list of messages <tt>Service.IMessaging.GetList(criteria)</tt> method is used.
+
 
<tt>criteria</tt> is the object which represents what messages we have to get.
+
To get a list of messages, <tt>Service.IMessaging.GetList(criteria)</tt> method is used. <tt>criteria</tt> is the object representing which messages to get.
To get list of incoming messages <tt>criteria.Type = "Inbox"</tt> is used.
+
To get a list of incoming messages <tt>criteria.Type = "Inbox"</tt> is used.
To remove selected message <tt>Service.IMessaging.Delete(criteria)</tt> method is used with <tt>criteria.MessageId</tt> set to message id of message which is selected.
+
To remove selected message, <tt>Service.IMessaging.Delete(criteria)</tt> method is used with <tt>criteria.MessageId</tt> set to message ID of the selected message.
To obtain access to service object for the Messaging Service API method
+
 
 +
To obtain access to the service object for the Messaging Service API, method
 
<tt>getServiceObject("Service.Messaging", "IMessaging")</tt> is used.
 
<tt>getServiceObject("Service.Messaging", "IMessaging")</tt> is used.
  
Line 233: Line 233:
  
 
==Postconditions==
 
==Postconditions==
* After starting the snippet list of messages, "Remove" button and "SMS/MMS"checkbox are shown on display.
+
* After starting the snippet list of messages, the "Remove" button and the "SMS/MMS" checkbox are shown on display.
* To remove any message - user should select it in the list and choose "Remove" button.
+
* To remove any message the user should select it from the list and press "Remove".
* After that required message will be deleted from phone's memory and from message list.
+
* The required message will be deleted from device memory and from message list.
* If checkbox is set to "sms" sms messages are processed;
+
* If checkbox is set to "sms", sms messages are processed.
* If checkbox is set to "mms" mms messages are processed.
+
* If checkbox is set to "mms", mms messages are processed.
  
 
==Supplementary material==
 
==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|Removing_message_from_Inbox_in_WRT.zip]]
+
You can view source file and executable application in the attached zip archive. The archive is available for download at [[Media:Removing_message_from_Inbox_in_WRT.zip|Removing_message_from_Inbox_in_WRT.zip]]
  
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Cateogry:Messaging]][[Category:S60 5th Edition]]
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Cateogry:Messaging]][[Category:S60 5th Edition]]

Revision as of 11:25, 18 December 2008


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: copyeditor (18 Dec 2008)


Overview

This code snippet shows how to delete a message from the Messaging inbox using the Messaging Platform Service for S60 Web Runtime, introduced in S60 5th Edition. It shows a list of inbox messages (sms or mms) and allows user to delete any of them.

The code snippet uses JavaScript WRT Messaging Services API.

To get a list of messages, Service.IMessaging.GetList(criteria) method is used. criteria is the object representing which messages to get. To get a 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 the selected message.

To obtain access to the 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, the "Remove" button and the "SMS/MMS" checkbox are shown on display.
  • To remove any message the user should select it from the list and press "Remove".
  • The required message will be deleted from device 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 view source file and executable application in the attached zip archive. The archive is available for download at Removing_message_from_Inbox_in_WRT.zipCateogry:Messaging

124 page views in the last 30 days.
×