×
Namespaces

Variants
Actions
(Difference between revisions)

MIME type handling in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
ivruban (Talk | contribs)
(New page: __NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id=  |platform=S60 5th Edition |devices=Nokia 5800 XpressMusic |category=Web Runtime (WRT) |subcategory=Files/Data |creationdate=January 29,...)
 
croozeus (Talk | contribs)

Revision as of 13:52, 26 February 2009


Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Keywords: device.getServiceObject(),Service.IAppManager.LaunchDoc(),

menu.setRightSoftkeyLabel(),widget.setNavigationEnabled(),

Service.IDataSource.GetList()
Created: (29 Jan 2009)
Last edited: croozeus (26 Feb 2009)


Overview

This code snippet shows how to use methods of AppManager Service API to launch an application based on a given document. Image files were chosen to present the mime type handling in WRT.

To obtain access to service object for the Media Management Service API, method getServiceObject("Service.MediaManagement", "IDataSource") used. After setting values for mediaCriteria.Type, mediaCriteria.Filter, mediaCriteria.Filter.FileType, mediaCriteria.Sort and mediaCriteria.Sort.Key method IDataSource.GetList(mediaCriteria, callback) is used.

Note, that IDataSource.GetList(mediaCriteria, callback) is asynchronous method, parameter callback - callback handler, was used for asynchronous call.

To obtain access to service object for the AppManager Service API, method getServiceObject("Service.AppManager", "IAppManager") used.

To obtain access to service object for the AppManagement Service API, method getServiceObject("Service.AppManager", "IAppManager") used.

After setting values for loCriteria.Document.DocumentPath method IAppManager.LaunchDoc(loCriteria) is used to launch a standalone application for image mime type.

Source file: Relevant HTML components

<select size = "5" id = "imageList" onclick = "show();">
<option></option>
</select>

Source file: JavaScript file

window.onload = init;
 
//Object available through a Service API. Declare service object,
//that is used to access the multimedia services.
var miltimediaServiceObject = null;
//Declare the result of fetching file list.
var result = null;
/**
* Java Script function.
* Showing the selected image.
*/

function show() {
try {
//Getting service object for application management.
var lo = device.getServiceObject("Service.AppManager", "IAppManager");
} catch (ex) {
alert("Exception in getting application service object: " + ex);
}
var imageList = document.getElementById("imageList");
//Taking selected file list and adding it to the attachment of the
//message
for(var i = 0; i < imageList.options.length; i++) {
if (imageList.options[i].selected) {
//Criteria for application managment's launch document function
var loCriteria = new Object();
//Object for Document member of criteria
loCriteria.Document = new Object();
//Setting the path to file, that must be opened in standalone
//application
loCriteria.Document.DocumentPath = imageList.options[i].value;
//Opening the file in standalone application
try {
var res = lo.IAppManager.LaunchDoc(loCriteria);
//Error handling
if (res.ErrorCode != 0){
alert(res.ErrorCode + ' ; ' + res.ErrorMessage);
}
} catch(ex){
alert("Exception in launching document: " + ex);
}
}
}
}
/**
* Java Script function.
* Closing window.
*/

function rightSoftkeyFunction() {
window.close();
}
/**
* Java Script function, used object available through a Service API.
* Function of creating options in html <select>, used to view available
* files to send via mms.
* @param iterator List of files, same as result.ReturnValue
*/

function createFileList(iterator) {
var imageList = document.getElementById("imageList");
//Iterator is the list of the files.
//Reset to set pointer to the first element.
iterator.reset();
var item;
//Cleaning the file list.
while (imageList.length != 0) {
imageList.remove(0);
}
//Fetching values from iterator and addition it to the options.
//Value of option consist the full path.
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement("option");
node.value = item.FileNameAndPath;
node.appendChild(document.createTextNode(item.FileName +
item.FileExtension));
imageList.appendChild (node);
}
}
/**
* Java Script function, used object available through a Service API.
* Callback function used to handle results of fetching multimedia files.
* @param transId - This is a number representing the transaction
* that called the callback
* @param eventCode - This is a number representing the callback return
* status.
* @param result - This is 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("imageList").options[0].focus();
}
/**
* Java Script function, used object available through a Service API.
* Initializing main controls.
*/

 
// Initializes the widget
function init() {
try {
//Setting label and handler for right softkey.
menu.setRightSoftkeyLabel("Exit", rightSoftkeyFunction);
//Disabling navigation, cursor will not be shown.
widget.setNavigationEnabled(false);
} catch(e) {
alert("initialize menu error: " + e);
}
try {
//Getting service object, for multimedia.
miltimediaServiceObject =
device.getServiceObject("Service.MediaManagement", "IDataSource");
//Setting file criteria.
var mediaCriteria = new Object();
mediaCriteria.Type = "FileInfo";
mediaCriteria.Filter = new Object();
mediaCriteria.Filter.FileType = "Image";
mediaCriteria.Sort = new Object();
mediaCriteria.Sort.Key = "FileSize";
//Asynchronous function for fetching files.
result =
miltimediaServiceObject.IDataSource.GetList(mediaCriteria, callback);
} catch( exception ) {
alert("initialize error: " + exception);
}
}

Postconditions

After starting of snippet all available images names wil be loaded into list box.
Click on name of the image loads the image content and displaying it in standalone application.

Supplementary material

  • You can test the handling og mime type vibra in action in a simple, executable application into which this code snippet has been patched. The executables and source files are available for download at: Media:MimeTypeHandling.zip.
  • You can examine all the changes that are required to implement the above mentioned features in an application. The changes are provided in unified diff and color-coded diff formats: link_to_patchs
90 page views in the last 30 days.