×
Namespaces

Variants
Actions
(Difference between revisions)

Checking network state in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Tidy wiki text)
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]][[Category:Networking]]
__NOEDITSECTION__
+
{{Abstract|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.}}
{{KBCS}}
+
{{ArticleMetaData
+
|id=CS001234
+
|platform=S60 5th Edition
+
|devices=Nokia 5800 XpressMusic
+
|category=Web Runtime (WRT)
+
|subcategory=System information
+
|creationdate=December 18, 2008
+
|keywords=x-systeminfo-widget, SystemInfo.signalbars, SystemInfo.networkname, SystemInfo.networkregistrationstatus, device.getServiceObject(), Service.SysInfo, Service.SysInfo.GetInfo()
+
  
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
+
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= [[Media:Checking network state in WRT.zip]]
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia 5800 XpressMusic
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 5th Edition
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Dekuykin]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= x-systeminfo-widget, SystemInfo.signalbars, SystemInfo.networkname, SystemInfo.networkregistrationstatus, device.getServiceObject(), Service.SysInfo, Service.SysInfo.GetInfo()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20081210
 +
|author= [[User:Dekuykin]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001234
 
}}
 
}}
  
 
==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. This snippet demonstrates both versions.  
+
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''': 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).}}
  
 
==Source (WRT 1.0)==
 
==Source (WRT 1.0)==
  
 
Embed the SystemInfo widget into the document:
 
Embed the SystemInfo widget into the document:
 
 
<code xml>
 
<code xml>
 
<body>
 
<body>
Line 199: Line 205:
 
==Supplementary material==
 
==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]].
+
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]].
 
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]]
+
[[Category:Code Snippet]]
+

Revision as of 09:50, 5 October 2012

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 (05 Oct 2012)

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.

178 page views in the last 30 days.
×