Network monitoring

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

and you added the cordova network information plugin already?

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

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

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

Yes you can run this code in constructor

thanks i will use …

@aditya_1027 is it working for you?

Yes, I am using the same in my application.

@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

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

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