×
Namespaces

Variants
Actions
(Difference between revisions)

MIME type handling in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
seppo_fn (Talk | contribs)
tapla (Talk | contribs)
Line 12: Line 12:
 
Service.IDataSource.GetList()
 
Service.IDataSource.GetList()
 
}}
 
}}
 
  
 
==Overview==
 
==Overview==
This code snippet shows how to launch an application based on a given document using AppManager Platform Service for Web Runtime, introduced in S60 5th Edition. 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
 
<tt>getServiceObject("Service.MediaManagement", "IDataSource")</tt> used.
 
After setting values for <tt>mediaCriteria.Type</tt>,
 
<tt>mediaCriteria.Filter</tt>, <tt>mediaCriteria.Filter.FileType</tt>,
 
<tt>mediaCriteria.Sort</tt> and <tt>mediaCriteria.Sort.Key</tt> method
 
<tt>IDataSource.GetList(mediaCriteria, callback)</tt> is used.
 
 
Note, that <tt>IDataSource.GetList(mediaCriteria, callback)</tt> is asynchronous method,
 
parameter <tt>callback</tt> - callback handler, was used for asynchronous call.
 
 
To obtain access to service object for the AppManager Service API, method
 
<tt>getServiceObject("Service.AppManager", "IAppManager")</tt> used.
 
 
To obtain access to service object for the AppManagement Service API, method
 
<tt>getServiceObject("Service.AppManager", "IAppManager")</tt> used.
 
  
After setting values for <tt>loCriteria.Document.DocumentPath</tt> method
+
This code snippet shows how to launch an application based on a given document using AppManager Platform Service for Web Runtime, introduced in S60 5th Edition. Image files were chosen to present the mime type handling in WRT.
<tt>IAppManager.LaunchDoc(loCriteria)</tt> is used to launch a standalone
+
application for image mime type.
+
  
 
==Source file: Relevant HTML components==
 
==Source file: Relevant HTML components==
Line 44: Line 24:
 
</code>
 
</code>
  
==Source file: JavaScript file==
+
==Source==
  
 
<code javascript>
 
<code javascript>
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.
+
* Shows the selected image.
* Showing the selected image.
+
*/
*/
+
 
function show() {
 
function show() {
 +
    var so = null;
 +
   
 
     try {
 
     try {
 
         //Getting service object for application management.
 
         //Getting service object for application management.
         var lo = device.getServiceObject("Service.AppManager", "IAppManager");
+
         var so = device.getServiceObject("Service.AppManager", "IAppManager");
    } catch (ex) {
+
    } catch (ex) {
 
         alert("Exception in getting application service object: " + ex);
 
         alert("Exception in getting application service object: " + ex);
    }
+
        return;
 +
    }
 +
 
 
     var imageList = document.getElementById("imageList");
 
     var imageList = document.getElementById("imageList");
    //Taking selected file list and adding it to the attachment of the
+
     for (var i = 0; i < imageList.options.length; i++) {
    //message
+
     for(var i = 0; i < imageList.options.length; i++) {
+
 
         if (imageList.options[i].selected) {
 
         if (imageList.options[i].selected) {
            //Criteria for application managment's launch document function
+
             var criteria = new Object();
             var loCriteria = new Object();
+
             criteria.Document = new Object();
             //Object for Document member of criteria
+
             //Setting the path to file that must be opened in a standalone
            loCriteria.Document = new Object();
+
             //Setting the path to file, that must be opened in standalone
+
 
             //application
 
             //application
             loCriteria.Document.DocumentPath = imageList.options[i].value;
+
             criteria.Document.DocumentPath = imageList.options[i].value;
 
             //Opening the file in standalone application
 
             //Opening the file in standalone application
 
             try {
 
             try {
                 var res = lo.IAppManager.LaunchDoc(loCriteria);
+
                 var res = so.IAppManager.LaunchDoc(criteria);
                //Error handling
+
 
                 if (res.ErrorCode != 0){
 
                 if (res.ErrorCode != 0){
 
                     alert(res.ErrorCode + ' ; ' + res.ErrorMessage);
 
                     alert(res.ErrorCode + ' ; ' + res.ErrorMessage);
 
                 }
 
                 }
             } catch(ex){
+
             } catch (ex){
 
                 alert("Exception in launching document: " + 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);
 
 
     }
 
     }
 
}
 
}
Line 177: Line 65:
 
==Postconditions==
 
==Postconditions==
  
After starting of snippet all available images names wil be loaded into list box.<br>
+
The image that is selected in the list, is displayed in a standalone application.
Click on name of the image loads the image content and displaying it in standalone application.
+
 
 +
==See also==
 +
 
 +
* [[CS001245 - Loading images in WRT]]
  
 
==Supplementary material==
 
==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]].
+
This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful for developers. The version of the WRT stub application used as a template in this snippet is v1.1.
  
* 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]]
+
* The patched, executable application that can be used to test the features described in this snippet is available for download at [[Media:MimeTypeHandling.zip]].
 +
* You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in [[Media:MimeTypeHandling.diff.zip]].
 +
* For general information on applying the patch, see [[Using Diffs]].
 +
* For unpatched stub applications, see [[Example stub]].
  
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 5th Edition]]
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]][[Category:Files/Data]][[Category:S60 5th Edition]]

Revision as of 10:39, 13 May 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: tapla (13 May 2009)

Overview

This code snippet shows how to launch an application based on a given document using AppManager Platform Service for Web Runtime, introduced in S60 5th Edition. Image files were chosen to present the mime type handling in WRT.

Source file: Relevant HTML components

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

Source

/**
* Shows the selected image.
*/

function show() {
var so = null;
 
try {
//Getting service object for application management.
var so = device.getServiceObject("Service.AppManager", "IAppManager");
} catch (ex) {
alert("Exception in getting application service object: " + ex);
return;
}
 
var imageList = document.getElementById("imageList");
for (var i = 0; i < imageList.options.length; i++) {
if (imageList.options[i].selected) {
var criteria = new Object();
criteria.Document = new Object();
//Setting the path to file that must be opened in a standalone
//application
criteria.Document.DocumentPath = imageList.options[i].value;
//Opening the file in standalone application
try {
var res = so.IAppManager.LaunchDoc(criteria);
if (res.ErrorCode != 0){
alert(res.ErrorCode + ' ; ' + res.ErrorMessage);
}
} catch (ex){
alert("Exception in launching document: " + ex);
}
}
}
}

Postconditions

The image that is selected in the list, is displayed in a standalone application.

See also

Supplementary material

This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful for developers. The version of the WRT stub application used as a template in this snippet is v1.1.

  • The patched, executable application that can be used to test the features described in this snippet is available for download at Media:MimeTypeHandling.zip.
  • You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in Media:MimeTypeHandling.diff.zip.
  • For general information on applying the patch, see Using Diffs.
  • For unpatched stub applications, see Example stub.
141 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.

×