Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Checking network state in Symbian Web Runtime

From Wiki
Jump to: navigation, search

This code example shows how to obtain information (network name, signal strength, and network registration status) about the currently available network on Symbian Web Runtime.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
CompatibilityArticle
Keywords: x-systeminfo-widget, SystemInfo.signalbars, SystemInfo.networkname, SystemInfo.networkregistrationstatus, device.getServiceObject(), Service.SysInfo, Service.SysInfo.GetInfo()
Created: dekuykin (10 Dec 2008)
Last edited: hamishwillee (03 May 2013)

Contents

Overview

The example uses the SystemInfo Service API. There are two versions of this particular API, one for WRT 1.0 and one for WRT 1.1. This snippet demonstrates both versions.

Note.pngNote: The SystemInfo Service API for WRT 1.1 is only available from S60 5th Edition onwards. The API for WRT 1.0 is supported from S60 3rd Edition, Feature Pack 2 onwards and also in selected S60 3rd Edition, Feature Pack 1 devices or their newest firmware versions (for example, Nokia E90 Communicator, from v.210.34.75 onwards).

Source (WRT 1.0)

Embed the SystemInfo widget into the document:

<body>
<embed type="application/x-systeminfo-widget" hidden="yes" />
</body>

Add also the components into which the information is printed:

<table>
<tr><td>Signal strength:</td><td id="signalStrength"></td></tr>
<tr><td>Network name:</td><td id="networkName"></td></tr>
<tr><td>Network state:</td><td id="networkState"></td></tr>
</table>

After that, the information can be obtained:

var sysInfo = null;
 
window.onload = init;
 
function init() {
// Obtain the SystemInfo object
try {
sysInfo = document.embeds[0];
} catch (ex) {
alert("SystemInfo object cannot be found.");
return;
}
// Update network information every half second
setInterval(updateNetworkData, 500);
}
 
function updateNetworkData() {
// Get signal strength
var signalStrength = sysInfo.signalbars;
document.getElementById("signalStrength").innerHTML = signalStrength;
 
// Get network name
var networkName = sysInfo.networkname;
document.getElementById("networkName").innerHTML = networkName;
 
// Get network registration status of the device
var networkRegistrationStatus = sysInfo.networkregistrationstatus;
var statusText = "";
switch (networkRegistrationStatus) {
case 0:
statusText = "Unknown";
break;
case 1:
case 2:
case 3:
statusText = "Not registered";
break;
case 4:
statusText = "Registered, network busy";
break;
case 5:
statusText = "Registered on home network";
break;
case 6:
statusText = "Registration denied";
break;
case 7:
statusText = "Registered on visited network (roaming)";
break;
default:
statusText = "Unknown";
break;
}
 
document.getElementById("networkState").innerHTML = statusText;
}

Source (WRT 1.1)

var serviceObj = null;
 
window.onload = init;
 
function init() {
// Obtain the SystemInfo service object
try {
serviceObj = device.getServiceObject("Service.SysInfo", "ISysInfo");
} catch (ex) {
alert("Service object cannot be found.");
return;
}
// Update network information every half second
setInterval(updateNetworkData, 500);
}
 
function updateNetworkData() {
// Initialize the criteria for the service object and obtain the
// information
var criteria = new Object();
criteria.Entity = "Network";
 
// Get signal strength
criteria.Key = "SignalStrength";
try {
var result = serviceObj.ISysInfo.GetInfo(criteria,
displaySignalStrength);
} catch (ex) {
alert(ex);
return;
}
 
// Get network name
criteria.Key = "CurrentNetwork";
try {
var result = serviceObj.ISysInfo.GetInfo(criteria,
displayNetworkName);
} catch (ex) {
alert(ex);
return;
}
 
// Get network registration status of the device
criteria.Key = "RegistrationStatus";
try {
var result = serviceObj.ISysInfo.GetInfo(criteria);
displayRegistrationStatus(result);
} catch (ex) {
alert(ex);
return;
}
}
 
function displaySignalStrength(transId, eventCode, result) {
// On error situation, display the error message
if (eventCode == 4) {
alert("Error " + result.ErrorCode + ": " + result.ErrorMessage);
return;
}
 
var signalStrength = result.ReturnValue.Status;
document.getElementById("signalStrength").innerHTML =
signalStrength + " dB";
}
 
function displayNetworkName(transId, eventCode, result) {
// On error situation, display the error message
if (eventCode == 4) {
alert("Error " + result.ErrorCode + ": " + result.ErrorMessage);
return;
}
 
var networkName = result.ReturnValue.NetworkName;
document.getElementById("networkName").innerHTML = networkName;
}
 
function displayRegistrationStatus(result) {
var networkRegistrationStatus = result.ReturnValue.Status;
document.getElementById("networkState").innerHTML =
networkRegistrationStatus;
}

Postconditions

Information about the current network is obtained.

Supplementary material

You can view the source file and executable application in the attached ZIP archive. The archive is available for download at Media:Checking network state in WRT.zip.

This page was last modified on 3 May 2013, at 07:16.
86 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.

×