Controlling vibration in Symbian Web Runtime
Article Metadata
Code Example
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition FP2 and later
Article
Keywords: x-systeminfo-widget, SystemInfo.startvibra(), SystemInfo.stopvibra()
Created: dekuykin
(26 Feb 2009)
Last edited: hamishwillee
(04 Oct 2012)
Contents |
Overview
This code snippet demonstrates how to use the device's vibration function by using the SystemInfo Service API of the Web Runtime version 1.0.
The API is supported from S60 3rd Edition FP2 onwards. It is also supported in select S60 3rd Edition, Feature Pack 1 devices or their newest firmware versions (for example, Nokia E90 Communicator, from v.210.34.75 onwards).
Source file: Relevant HTML components
<embed type="application/x-systeminfo-widget" hidden="yes" />
<input id="startVibraButton" type="button" value="Start vibra"
onclick="startVibra();" />
<input id="stopVibraButton" type="button" value="Stop vibra"
onclick="stopVibra();" />
<p>Vibra intensity</p>
<input type="radio" name="intensity" id="min" value="min" />
<label for="min">Minimal</label>
<input type="radio" name="intensity" id="mid" value="min" />
<label for="mid">Middle</label>
<input type="radio" name="intensity" id="max" value="min" />
<label for="max">Maximal</label>
Source
// Global variable for System Info object
var sysinfo = null;
window.onload = init;
// Initializes the widget
function init() {
// Get access to SystemInfo API
initSysInfo();
// ...
// Set default vibra intensity to minimum value
document.getElementById('min').checked = true;
}
/**
* Obtain reference to SystemInfo API from embedded object.
*/
function initSysInfo() {
try {
// Get access to SystemInfo API
sysinfo = document.embeds[0];
} catch (e) {
alert('Setup error: ' + e);
}
}
function startVibra() {
// Set vibra intensity to minimum value
var vibraIntensity = sysinfo.vibraminintensity;
try {
if (document.getElementById('mid').checked) {
// Set vibra intensity to middle value
vibraIntensity = Math.ceil((sysinfo.vibraminintensity +
sysinfo.vibramaxintensity) / 2);
}
} catch (e) {
alert("Error: " + e);
}
try {
if (document.getElementById('max').checked) {
// Set vibra intensity to maximum value
vibraIntensity = sysinfo.vibramaxintensity;
}
} catch (e) {
alert("Error: " + e);
}
// Start vibra
sysinfo.startvibra(sysinfo.vibramaxduration, vibraIntensity);
alert("Vibration started!");
}
function stopVibra() {
// Stop vibra
sysinfo.stopvibra();
alert("Vibration stopped!");
}
Postconditions
Different possibilities for controlling the vibration are demonstrated.
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 to 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:Controlling vibra in WRT.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:ControllingVibra.diff.zip.
- For general information on applying the patch, see Using Diffs.
- For unpatched stub applications, see Example app stubs with logging framework.


Inheaven - Do not works in NOKIA C5-03
I have downloaded the example code package from this documentation page and uploaded it to my hosting account. Here it is https://bobdn.com/WRT/wrtstub.html. (u would see nothing on this page from desktop browser)
I tried opening this from my Symbian S60 (Nokia C5-03) device. I can see the page content. But When I do click on 'Start Vibrate' or 'Stop Vibrate' button. It opens success alert for both commands. This means there was no exception thrown (exception has handled).
Why my mobile do not vibrates..?? I have not try this on other Symbian devices.inheaven 14:54, 12 April 2012 (EEST)