Namespaces
Variants
Actions

Controlling vibration in Symbian Web Runtime

Jump to: navigation, search
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.

This page was last modified on 4 October 2012, at 08:45.
257 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved