You Are Here:

Community: Wiki

This page was last modified on 20 January 2009, at 07:34.

CS001239 - Sending MMS messages in WRT

From Forum Nokia Wiki



ID CS001242 Creation date December 18, 2008
Platform S60 5th Edition Tested on devices
Category Web Runtime (WRT) Subcategory Messaging


Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.Messaging.Send(), Service.Messaging.GetList(),

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.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fCS001239E5fE2dE5fSendingE5fMMSE5fmessagesE5finE5fWE52TX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZmediaQ qfnZtopicQUqfnTopicZmessagingQ qfnZtopicQUqfnTopicZmmsQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxmessagingX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx1E2E0000X