NetworkInformation API
Original documentation: Cordova Network Information.
Remark: Usage of cordova API needs http://tizen.org/privilege/filesystem.read privilege.
Since: 3.0
Table of Contents
- 1. Interfaces
- 1.1. NetworkInformationManagerObject
- 1.2. NetworkInformationManager
- 1.3. Connection
- 1.4. OnlineEventCallback
- 1.5. OfflineEventCallback
- 2. Related Feature
- 3. Full WebIDL
Summary of Interfaces and Methods
Interface | Method |
---|---|
NetworkInformationManagerObject | |
NetworkInformationManager | |
Connection | |
OnlineEventCallback | void online () |
OfflineEventCallback | void offline () |
1. Interfaces
1.1. NetworkInformationManagerObject
[NoInterfaceObject] interface NetworkInformationManagerObject { readonly attribute NetworkInformationManager connection; };
Navigator implements NetworkInformationManagerObject;
Since: 3.0
The navigator.connection object allows access to the NetworkInformation API.
1.2. NetworkInformationManager
[NoInterfaceObject] interface NetworkInformationManager { readonly attribute DOMString type; };
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Attributes
-
readonly
DOMString typeReturns the current connection type. The value returned is one of the following strings, case-sensitively: unknown, ethernet, wifi, 2g, 3g, 4g, none.
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/telephony
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
function checkConnection() { var networkState = navigator.connection.type; var states = {}; states[Connection.UNKNOWN] = "Unknown connection"; states[Connection.ETHERNET] = "Ethernet connection"; states[Connection.WIFI] = "WiFi connection"; states[Connection.CELL_2G] = "Cell 2G connection"; states[Connection.CELL_3G] = "Cell 3G connection"; states[Connection.CELL_4G] = "Cell 4G connection"; states[Connection.CELL] = "Cell generic connection"; states[Connection.NONE] = "No network connection"; alert("Connection type: " + states[networkState]); } checkConnection();
Output example:
Connection type: Cell 3G connection
1.3. Connection
interface Connection { readonly attribute DOMString UNKNOWN; readonly attribute DOMString ETHERNET; readonly attribute DOMString WIFI; readonly attribute DOMString CELL_2G; readonly attribute DOMString CELL_3G; readonly attribute DOMString CELL_4G; readonly attribute DOMString CELL; readonly attribute DOMString NONE; };
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Attributes
-
readonly
DOMString UNKNOWNThe value returned is "unknown".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.UNKNOWN);
Output example:
unknown
-
readonly
DOMString ETHERNETThe value returned is "ethernet".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.ETHERNET);
Output example:
ethernet
-
readonly
DOMString WIFIThe value returned is "wifi".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.WIFI);
Output example:
wifi
-
readonly
DOMString CELL_2GThe value returned is "2g".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.CELL_2G);
Output example:
2g
-
readonly
DOMString CELL_3GThe value returned is "3g".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.CELL_3G);
Output example:
3g
-
readonly
DOMString CELL_4GThe value returned is "4g".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.CELL_4G);
Output example:
4g
-
readonly
DOMString CELLThe value returned is "cellular".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.CELL);
Output example:
cellular
-
readonly
DOMString NONEThe value returned is "none".
Since: 3.0
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
console.log(Connection.NONE);
Output example:
none
1.4. OnlineEventCallback
[NoInterfaceObject, Callback=FunctionOnly] interface OnlineEventCallback { void online(); };
Since: 3.0
The online event fires when an application goes online, and the device becomes connected to the Internet.
Applications typically should use document.addEventListener() to attach an event listener once the deviceready event fires.
Original documentation: Cordova online event
Code example:
document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("online", onOnline, false); } function onOnline() { /* Handle the online event. */ }
1.5. OfflineEventCallback
[NoInterfaceObject, Callback=FunctionOnly] interface OfflineEventCallback { void offline(); };
Since: 3.0
The online event fires when an application goes online, and the device becomes connected to the Internet.
Applications typically should use document.addEventListener() to attach an event listener once the deviceready event fires.
Original documentation: Cordova offline event
Code example:
document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("offline", onOffline, false); } function onOffline() { /* Handle the offline event. */ }
2. Related Feature
To guarantee that the NetworkInformation application runs on a device with the NetworkInformation feature declare the following feature requirements in the config file:
3. Full WebIDL
module NetworkInformation { Navigator implements NetworkInformationManagerObject; [NoInterfaceObject] interface NetworkInformationManagerObject { readonly attribute NetworkInformationManager connection; }; [NoInterfaceObject] interface NetworkInformationManager { readonly attribute DOMString type; }; interface Connection { readonly attribute DOMString UNKNOWN; readonly attribute DOMString ETHERNET; readonly attribute DOMString WIFI; readonly attribute DOMString CELL_2G; readonly attribute DOMString CELL_3G; readonly attribute DOMString CELL_4G; readonly attribute DOMString CELL; readonly attribute DOMString NONE; }; [NoInterfaceObject, Callback=FunctionOnly] interface OnlineEventCallback { void online(); }; [NoInterfaceObject, Callback=FunctionOnly] interface OfflineEventCallback { void offline(); }; };