Network monitoring


#1

in html

document.addEventListener("online", onOnline, false);

in typescript

onOnline()
{
network checking status code
}

i want to know when user have internet connection and when not have

.
any idea


#2

and you added the cordova network information plugin already?


#3

You will need to import Network from ionic-native, Then use below code:

Network.onDisconnect().subscribe(() => {
/* Your code */
});
Network.onConnect().subscribe(() => {
/* Your code */
});

#4

yes i have installed plugin
where should i use this code . within constructor.

will this give information if internet access get blocked during application run


#5

Yes you can run this code in constructor


#6

thanks i will use …


#7

@aditya_1027 is it working for you?


#8

Yes, I am using the same in my application.


#9

@aditya - hey for me,its not alerting whether network is there or not
see i am using same code as yours in constructor
Network.onDisconnect().subscribe(() => {
alert(‘network was disconnected’);
});
Network.onConnect().subscribe(() => {
alert("network connected ");
});

any help would be appreciated.Thanks in advance


#10

Can you please share the file or whole code? So then i can check and help you.


#11

@aditya - sorry, its working…
i was not connecting and disconnecting internet to check functionality.
thankyou so much…!!