| ID | CS001160 | Creation date | October 30, 2008 |
| Platform | S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Web Runtime (WRT) | Subcategory | S60 Platform Services |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.AppManager |
This code snippet demonstrates how to use the AppManager Service API to discover the applications that are installed on the device.
<?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="script.js" /> <title>WRT Application</title> </head> <body> <div id="bodyContent" class="bodyContent"> </div> </body> </html>
var serviceObj = null; window.onload = init; // Initializes the widget function init() { // Obtain the AppManager service object try { serviceObj = device.getServiceObject("Service.AppManager", "IAppManager"); } catch (ex) { alert("Service object cannot be found."); return; } // We are interested in applications, so let's define the criteria // respectively var criteria = new Object(); criteria.Type = "Application"; // Obtain the list of installed applications var result = serviceObj.IAppManager.GetList(criteria); var appList = createAppList(result.ReturnValue); appList.sort(); displayList(appList); } // Creates the list of installed applications function createAppList(iterator) { var list = new Array(); try { iterator.reset(); var item; while ((item = iterator.getNext()) != undefined) { var txt = ""; txt += item.Caption + " ("; txt += item.Uid + ")"; list.push(txt); } } catch (ex) { alert(ex); } return list; } // Displays a list on the screen function displayList(list) { var listElement = document.createElement("ol"); for (var i = 0; i < list.length; i++) { var listItemElement = document.createElement("li"); var textElement = document.createTextNode(list[i]); listItemElement.appendChild(textElement); listElement.appendChild(listItemElement); } var bodyContentElement = document.getElementById("bodyContent"); bodyContentElement.appendChild(listElement); }
The example displays an alphabetically ordered list of installed applications and their UIDs on an HTML page.