Languages

Menu
Sites
Language
Network error popup code not working as expected in Tizen Tv Web App

Hi,

I am working on a Tizen tv web application where I need to check if it is connected to the network or not. I tried samples given on samsungDforums  but they are not showing me the correct result.

Following is the code which I tried to use:

var myInterval = setInterval(function () {

    if(webapis.network.getGateway() !== null){

        console.log("network is ok");

        alert("network is ok.");

    }else{

        alert("您的设备目前已和网络断开, 请查看您的网络后重新尝试连接.");

    }

},30000); 

Even when I switch off the wifi on the tv or on my system while running the emulator, it always tells me the network is ok.

 

If I use the following(as given in the sample code site):

// Check network connection 
    var myInterval = setInterval(function () {
    	if(Network.getGateway()!=null){
    		document.getElementById('ep').style.display='inline';
//Network error message in pop up
    		document.getElementById('ErrorPopUp').innerHTML="No Network Found";
    	}else{
    		document.getElementById('ep').style.display='none';
    	}
    },1000); 

It still doesn't give me the correct result.  

 

I'll appreciate if someone can help me in this. Thanks in advance!

Edited by: Kinjal Dua on 25 Sep, 2016

Responses

3 Replies
Armaan-Ul- Islam

Hello,

You can try this to check the network status..

var isOnline = navigator.onLine;

if(isOnline) {   
    console.log("network is ok");
    alert("network is ok.");
    // DO YOU CODE FOR ONLINE STATE
} 
else {       
    alert("您的设备目前已和网络断开, 请查看您的网络后重新尝试连接.");
    // DO YOU CODE FOR OFFLINE STATE
}
Kinjal Dua

Thanks alot armaan! 

Do you happen to know how to disable network on tizen tv for testing. When I disconnect wifi from the settings on the tv the code to detect network lost doesn't work! is there a different way to disconnect network on tv?

Armaan-Ul- Islam