$cordovaNetwork returns me false even if I am connected

I am using $cordovaNetwork to know when my project is connected to network and when not. I am using the method isOnline(), and it returns false. But it is not true, because I know I am connected when the device is ready. I have some information that I catch from internet that is loaded in the beginning, so I have connection to internet.

When the event online is fired up? When $cordovaNetwork knows really that the application is online? Sometimes it shows me that there is connection (TRUE) but sometimes it shows me that there isn’t (FALSE).

Finally, I use that application, so I have change the state, and then $cordoaNetwork.isonline() returns me FALSE, very strange.

Can any one help me? The documentation is not very extensive. And If you can, give some example, please. If need more information, ask me.


did you added the cordova network-information plugin to your project?

Yes, I did. My problem is that $cordovaNetwork.isOnline() don’t know that I have a connection since the beginning. I have done the next steps:

  • Open a terminal and write “nvm use v4.2.3” to have the correct version of nodejs active.
  • Go to the folder of project, in my case, “cd /var/phone/myProject”
  • Write “ionic run android”.
  • Wait some seconds until the application is up.

Until here, I don’t have problems. The application is built well. Then, I use $cordovaNetwork in order to monitoring the states of online and offline, when is active in a moment. $cordovaNetwork.isOnline() works, but It appears that sometimes don’t know when one state or another is really active. All the times that I run the application, I know that is connected because some of the code is in a server, so if it is not loaded, it will appear blank.

So knowing that the event online is active, why $cordovaNetwork.isOnline() doesn’t detect it? I was looking for the solution in other forums, but it appears that nobody has had this problem.

Perhaps the problem is in the emulator? Before I use the command “ionic run android”, I have to open other terminal and write “android avd” to have a platform of android open to use the application. I have not tested it in a phone.

Thanks for your help

strange :confounded:

i would say --> test it on a real device (it is very easy with ionic cli --> connect your device, check if device detected with the ‘adb devices’ and call ionic run android again --> it should install the app on your device)

if (window.Connection) {
  if (navigator.connection.type == Connection.NONE) {
    //No Connection
    //Connection Available

i think this is clear… but you have to handle offline/online events, if the device goes offline or online during execution… and this events are not firing here…

it is worked for me any doubts please give number

Hi, thanks for your answers,

I’ve been a little busy with other things, sorry. I will try this night the options you give to me. And I will say If I still have problems.

Again, thank you.