| ID | CS001162 | Creation date | October 30, 2008 |
| Platform | S60 3rd Edition, FP2 S60 5th Edition | Tested on devices | Nokia N96 Nokia 5800 XpressMusic |
| Category | Web Runtime (WRT) | Subcategory | S60 Platform Services |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.AppManager, widget.openApplication() |
This code snippet demonstrates how to launch an installed application from a widget. The snippet describes two approaches:
The first approach is only available on devices that support S60 Platform Services. The second approach is available in every widget.
Note: For security reasons, the second approach cannot be used to launch a widget. This restriction does not apply for the first approach.
<?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"/>
<link rel="StyleSheet" href="style/general.css" type="text/css" />
<script type="text/javascript" src="script/script.js" />
<title>WRT Application</title>
</head>
<body>
<div id="bodyContent" class="bodyContent">
<!-- When the button is clicked, launch the application with the
UID of 0x100058F8 (the Profiles application) -->
<input type="button" value="Launch" onclick="launchApp('0x100058F8');" />
</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;
}
}
// Launches an application with the specified UID
function launchApp(uid) {
if (serviceObj != null) {
launchApp5thEd(uid);
} else {
launchApp3rdEd(uid);
}
}
// Launches an application with the specified UID by using the platform service
// object (only available on 5th Edition devices)
function launchApp5thEd(uid) {
var criteria = new Object();
criteria.ApplicationID = "s60uid://" + uid;
var result = serviceObj.IAppManager.LaunchApp(criteria);
if (result.ErrorCode != 0) {
alert(result.ErrorCode + ": " + result.ErrorMessage);
}
}
// Launches an application with the specified UID by using the WRT widget
// object (available in every WRT device)
function launchApp3rdEd(uid) {
// The openApplication method requires that UID is an integer, not a string
uid = parseInt(uid);
widget.openApplication(uid, "");
}
The application with the specified UID (0x100058F8, the Profiles application) is launched.