×
Namespaces

Variants
Actions
(Difference between revisions)

Checking network state in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
tapla (Talk | contribs)
Forum Nokia KB (Talk | contribs)
m
Line 14: Line 14:
 
==Overview==
 
==Overview==
  
This code snippet shows how to obtain information (network name, signal strength, and network registration status) about the currently available network by using the SystemInfo Service API of the Web Runtime (WRT). There are two versions of this particular API, one for WRT 1.0 and one for WRT 1.1. Both versions are demonstrated in this snippet.  
+
This code snippet shows how to obtain information (network name, signal strength, and network registration status) about the currently available network by using the SystemInfo Service API of the Web Runtime (WRT). 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''': 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).
 
'''Note''': 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).

Revision as of 10:26, 20 January 2009


Template:KBCS

Article Metadata
Tested 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: (18 Dec 2008)
Last edited: Forum Nokia KB (20 Jan 2009)

Overview

This code snippet shows how to obtain information (network name, signal strength, and network registration status) about the currently available network by using the SystemInfo Service API of the Web Runtime (WRT). 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: 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.

67 page views in the last 30 days.