Most Web applications use a network connection to, for example, play media and download files. Because the network connection can disconnect and reconnect unexpectedly, checking the network status regularly is very important for application stability.
You can use the Samsung Product Network API to monitor network status changes and retrieve the current network status.
NoteIf your application content cannot be accessed due to HTTP client or server issues, you must show a clear error message with information on what to do or who to contact for support. Remember that Samsung cannot provide support to TV users with issues related to content availability within your application.
Prerequisites
To use the Network API, the application has to request permission by adding the following privilege to the "config.xml" file:
To receive notifications when the network status changes, add the addNetworkStateChangeListener() method to your window.onload event:
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
}
});
The callback returns NetworkState.GATEWAY_DISCONNECTED when the network has become disconnected. You must stop jobs requiring a network connection, such as network media playback and server request sending. Return the user to the previous page and inform them of the disconnected status using a popup.
The callback returns NetworkState.GATEWAY_CONNECTED when the network has reconnected.
Retrieving the Network Status
When resuming media playback, or resuming an application from the pause state, check the current network status. You can retrieve the current network status in 2 ways:
Using the getActiveConnectionType() method:
var activeConnectionType = webapis.network.getActiveConnectionType();
if (activeConnectionType == 0) {
// Something you want to do when network is disconnected
}
Using the isConnectedToGateway() method:
var gatewayStatus = webapis.network.isConnectedToGateway();
if (!gatewayStatus) {
// Something you want to do when network is disconnected
}
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.