×
Namespaces

Variants
Actions
Revision as of 09:29, 14 June 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Sending MMS messages in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.Messaging.Send(), Service.Messaging.GetList(),
Created: ivruban (10 Dec 2008)
Last edited: hamishwillee (14 Jun 2013)

Contents

Overview

This code snippet shows how to send MMS messages synchronously and asynchronously and attach images to messages using the Messaging and Media Management Platform Services for S60 Web Runtime introduced in S60 5th Edition.

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

To obtain access to the service object for the Media Management Service API, the device.getServiceObject("Service.MediaManagement", "IDataSource") method is used.

Source

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="sendMessage.js" />
<title></title>
</head>
<body>
<div id="bodyContent" class="bodyContent">
<input type="checkbox" id="async" />
<label for="async">Send asynchronously</label><br />
 
<label for="phoneNumber">Phone number:</label><br />
<input type="text" id="phoneNumber" size="12" maxlength="12" />
<br />
 
<label for="message">Message:</label><br />
<textarea id="message" cols="40" rows="3"></textarea><br />
 
<label for="fileList">Attachments:</label><br />
<select size="5" id="fileList" multiple></select><br />
 
<input type="button" value="Send" onclick="sendMMS();" />
</div>
</body>
</html>

Source: sendMessage.js

var messagingServiceObj = null;
var multimediaServiceObject = null;
 
window.onload = init;
 
// Initializes the widget
function init() {
try {
messagingServiceObj =
device.getServiceObject("Service.Messaging", "IMessaging");
 
multimediaServiceObject =
device.getServiceObject("Service.MediaManagement", "IDataSource");
 
//Setting the criteria for fetching images
var criteria = new Object();
criteria.Type = "FileInfo";
criteria.Filter = new Object();
criteria.Filter.FileType = "Image";
criteria.Sort = new Object();
criteria.Sort.Key = "FileSize";
result =
multimediaServiceObject.IDataSource.GetList(criteria, callback);
} catch (ex) {
alert("Error in initializing the widget");
return;
}
}
 
/**
* A callback function used to handle results of fetching multimedia files.
* @param transId A number representing the transaction that called the
* callback
* @param eventCode A number representing the callback return status
* @param result An object for holding the callback return value
*/

function callback(transId, eventCode, result) {
if(result.ErrorCode != 0) {
alert("Error in creating file list:" + result.ErrorCode);
return;
}
createFileList(result.ReturnValue);
document.getElementById("fileList").options[0].focus();
}
 
/**
* Creates a list item for every multimedia file in "iterator".
* @param iterator The list of files
*/

function createFileList(iterator) {
var fileList = document.getElementById("fileList");
//Reset to set pointer to the first element.
iterator.reset();
var item;
//Cleaning the file list.
while (fileList.length != 0) {
fileList.remove(0);
}
 
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement("option");
//Value of option consists of the full path.
node.value = item.FileNameAndPath;
node.appendChild(document.createTextNode(item.FileName +
item.FileExtension));
fileList.appendChild(node);
}
}
 
function sendMMS() {
var criteria = new Object();
//Setting the type of the message
criteria.MessageType = "MMS";
 
var phoneNumber = document.getElementById("phoneNumber").value;
if (phoneNumber != null) {
//Setting the "To" field of the message, can't be empty
criteria.To = phoneNumber;
} else {
alert("Phone number is empty");
return;
}
 
var messageText = document.getElementById("message").value;
if (messageText != null) {
//Setting the body text field of the message, can't be empty
criteria.BodyText = messageText;
} else {
alert("Text is empty");
return;
}
 
var fileList = document.getElementById("fileList");
//Adding the selected items as attachments of the message
for (var i = 0; i < fileList.options.length; i++) {
if (fileList.options[i].selected) {
criteria.Attachment = fileList.options[i].value;
}
}
 
try {
if (document.getElementById("async").checked == false) {
//Send the message synchronously
var result = messagingServiceObj.IMessaging.Send(criteria);
checkError(result);
} else {
//Send the message asynchronously
messagingServiceObj.IMessaging.Send(criteria, onSendDone);
}
} catch(exception) {
alert("SendMMS error: " + exception);
}
}
 
// Called when asynchronous message sending has been completed
function onSendDone(transId, eventCode, result) {
checkError(result);
}
 
function checkError(error) {
if (error.ErrorCode != 0) {
alert("Error in sending message");
} else {
alert("Message was sent succesfully");
}
}

Postconditions

  • When the snippet is started, the user can choose to send the MMS synchronously or asynchronously (check box).
  • Text fields are used to define the receiver's phone number and message contents.
  • The user can select the files to attach. A list box shows all files that can be selected.
  • The message is sent by pressing "Send".

Supplementary material

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

This page was last modified on 14 June 2013, at 09:29.
72 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×