top

Checking Network Status

This document covers how to check network status and handle.

Overview

Because most of applications use network for playing media, downloading files and etc, checking network status is very important for stability. Because of unexpected issues, network may be disconnected and reconnected in a few minutes. For this situation, you should check network status consistently and handle properly.

Please refer to the following for checking network and handling disconnect situation.

Checking Network Status and Handling

By using Samsung Product API, you can get network status. Please refer to Network API.

webapis.network.addNetworkStateChangeListener method is fired when network is disconnected and reconnected. Every time network status is changed, this method informs you network status.
You should add this mehod in window.onload function.

webapis.network.addNetworkStateChangeListener(function (value) {
	if (value == webapis.network.NetworkState.GATEWAY_DISCONNECTED){
 	// Something you want to do when network is disconnected.
	} else if(value == webapis.network.NetworkState.GATEWAY_CONNECTED){
 	// Something you want to do when network is connected again.
	}
});
  • If value of callback function is “webapis.network.NetworkState.GATEWAY_DISCONNECTED”, it means network became disconnected. We recommend you to stop doing current jobs like playing media contents or request something to server. And it’s better to return to previous page and to show “Network Check Popup” for the user which informs this status.

  • If value of callback function is “webapis.network.NetworkState.GATEWAY_CONNECTED”,
    it means network became reconnected. So you should handle properly.

If you want to get network status right now, you can call webapis.network.getActiveConnectionType or webapis.network.isConnectedToGateway method.

var activeConnectionType = webapis.network.getActiveConnectionType();

if(activeConnectionType == 0) {
	// Something you want to do when network is disconnected.
}

or

var gatewayStatus = webapis.network.isConnectedToGateway();
if (!gatewayStatus){
	//Something you want to do when network is disconnected.
}

We recommend to call it in case application is resumed, playing media contents and so on.

For calling these APIs, you should add the following privilege. Please note that.

<tizen:privilege name='http://developer.samsung.com/privilege/network.public'></tizen:privilege>

Sample Applications