×
Namespaces

Variants
Actions
(Difference between revisions)

Removing message from Inbox in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
dekuykin (Talk | contribs)
hamishwillee (Talk | contribs)
 
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
+
{{ArticleMetaData <!-- v1.2 -->
__NOEDITSECTION__
+
|sourcecode= [[Media:Removing message from Inbox in WRT.zip]]
{{CodeSnippet
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|id=&nbsp;
+
|devices= Nokia 5800 XpressMusic
|platform=S60 5th Edition
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|devices=Nokia 5800 XpressMusic
+
|platform= S60 5th Edition
|category=Web Runtime (WRT)
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|subcategory=S60 Platform Messaging Services
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|creationdate=November 24, 2008
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|keywords=device.getServiceObject(), Service.IMessaging.GetList(), Service.IMessaging.Delete()
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= device.getServiceObject(), Service.Messaging.Delete()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20081210
 +
|author= [[User:Dekuykin]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Messaging
 +
|id= CS001241
 
}}
 
}}
 
  
 
==Overview==
 
==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 <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 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 obtain access to service object for the Messaging Service API method
 
<tt>getServiceObject("Service.Messaging", "IMessaging")</tt> is used.
 
  
==Source file: RemovingMessage.html==
+
This code snippet shows how to delete a message from the Inbox using the Messaging Platform Service for S60 Web Runtime introduced in S60 5th Edition.
  
<code xml>
+
The {{Icode|device.getServiceObject("Service.Messaging", "IMessaging")}} method is used to get access to the service object for the Messaging Service API.
<!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>
+
==Source==
        <td colspan="2">
+
<select id="messageList" size="5" multiple>
+
  <option disabled> </option>
+
</select>
+
        </td>
+
      </tr>
+
    </table>
+
</body>
+
</html>
+
</code>
+
  
==Source file: removeMessage.css==
+
The HTML {{Icode|select}} component contains the messages:
  
<code css>
+
<code xml>
h2  {
+
<select size="5" id="messageList" multiple></select><br />
    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;
+
}
+
 
</code>
 
</code>
 
==Source file: removeMessage.js==
 
  
 
<code javascript>
 
<code javascript>
// removeMessage.js
+
var serviceObj = null;
  
// Object is available through a Service API. Declare service object,
+
// Initializes the widget
// that is used to access the messaging services.
+
function init() {
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 {
 
     try {
         document.getElementById("messageList").style.display = "none";
+
         serviceObj = device.getServiceObject("Service.Messaging",
        //Getting service object.
+
        serviceObject = device.getServiceObject("Service.Messaging",
+
 
             "IMessaging");
 
             "IMessaging");
     } catch (exception) {
+
     } catch (ex) {
         alert("Service initialization error: " + exception);
+
         alert("Service object cannot be found.");
 
         return;
 
         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();
 
 
}
 
}
/**
+
</code>
* 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
+
<code javascript>
    while (msgList.length > 0) {
+
// Removes the message which is selected in the list box.
     msgList.remove(0);
+
function removeMessage() {
    }
+
     // Get a reference to SELECT object which contains the list of messages
 +
    var messageList = document.getElementById("messageList");
  
 
    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();
 
     var criteria = new Object();
     // Find messages which are selected in selection listbox
+
     // Find the selected messages
     for (var msgIndex = 0; msgIndex < msgList.length; msgIndex++) {
+
     for (var msgIndex = 0; msgIndex < messageList.length; msgIndex++) {
         if (msgList.options[msgIndex].selected) {
+
         if (messageList.options[msgIndex].selected) {
             // Get message id of selected message
+
             // Get message id of the selected message
             var messageId = msgList.options[msgIndex].value;
+
             var messageId = messageList.options[msgIndex].value;
 
             // Radix of message id integer value
 
             // Radix of message id integer value
 
             var radix = 10;
 
             var radix = 10;
Line 219: Line 73:
 
             var result = serviceObject.IMessaging.Delete(criteria);
 
             var result = serviceObject.IMessaging.Delete(criteria);
 
             if (result.ErrorCode !== 0) {
 
             if (result.ErrorCode !== 0) {
 +
                alert("Error in deleting messages");
 
                 break;
 
                 break;
 
             }
 
             }
 
             // Remove message record from selection list
 
             // Remove message record from selection list
             msgList.remove(msgIndex);
+
             messageList.remove(msgIndex);
 
             msgIndex = msgIndex - 1;
 
             msgIndex = msgIndex - 1;
 
         }
 
         }
 
     }
 
     }
 
     getMessageList();
 
     getMessageList();
 
 
}
 
}
 
</code>
 
</code>
  
 
==Postconditions==
 
==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.
+
The selected SMS or MMS messages are deleted.
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==
 
==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]]
+
You can view the 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]].
 +
 
 +
==See also==
 +
 
 +
* [[Listing inbox messages in Symbian Web Runtime]]
  
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Messaging]][[Category:S60 5th Edition]][[Category:Code Snippet]]

Latest revision as of 07:40, 1 August 2012

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Messaging.Delete()
Created: dekuykin (10 Dec 2008)
Last edited: hamishwillee (01 Aug 2012)

Contents

[edit] Overview

This code snippet shows how to delete a message from the Inbox using the Messaging Platform Service for S60 Web Runtime introduced in S60 5th Edition.

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

[edit] Source

The HTML select component contains the messages:

<select size="5" id="messageList" multiple></select><br />
var serviceObj = null;
 
// Initializes the widget
function init() {
try {
serviceObj = device.getServiceObject("Service.Messaging",
"IMessaging");
} catch (ex) {
alert("Service object cannot be found.");
return;
}
}
// Removes the message which is selected in the list box.
function removeMessage() {
// Get a reference to SELECT object which contains the list of messages
var messageList = document.getElementById("messageList");
 
var criteria = new Object();
// Find the selected messages
for (var msgIndex = 0; msgIndex < messageList.length; msgIndex++) {
if (messageList.options[msgIndex].selected) {
// Get message id of the selected message
var messageId = messageList.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) {
alert("Error in deleting messages");
break;
}
// Remove message record from selection list
messageList.remove(msgIndex);
msgIndex = msgIndex - 1;
}
}
getMessageList();
}

[edit] Postconditions

The selected SMS or MMS messages are deleted.

[edit] Supplementary material

You can view the 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.

[edit] See also

This page was last modified on 1 August 2012, at 07:40.
76 page views in the last 30 days.
×