0

I want to check internet connection inside my app but cordova plugin is working with special versions so I started to think how can I do this? I find this code from this page How to check whether user has internet connection or not in Angular2?

export class LoginPage {
public onlineOffline: boolean = navigator.onLine;

  constructor(public navCtrl: NavController, public navParams: NavParams) {
    window.addEventListener('online', () => {this.onlineOffline = true});
    window.addEventListener('offline', () => {this.onlineOffline = false});

  }

  ionViewDidLoad() {
        console.log('ionViewDidLoad LoginPage');
  }
}

but it seems it check only network connectivity not internet connectivity. it shows true when connected to any network regardless that network providing internet access or not.

Any kind of help is welcome.

Community
  • 1
  • 1
RSA
  • 1,417
  • 4
  • 22
  • 37
  • why dont you just use https://github.com/apache/cordova-plugin-network-information plugin? – Sarantis Tofas Jan 22 '17 at 13:26
  • I hope [this](http://stackoverflow.com/q/20540150/2401386) helps you. – Blauharley Jan 22 '17 at 19:26
  • Dear @Akis that plug in is not working on in working on device with android version below 4.4. I want to support at least 4.0~4.4 devices with my application. – RSA Jan 23 '17 at 04:51
  • @Blauharley I've tried similar codes even that code i wrote above is showing that my network connection status is connected or no . but actually there is no internet connection checking. Ajax url test takes a time and real url fech is required more time, do you think user will appreciated from application with these waitings? – RSA Jan 23 '17 at 05:08
  • @Reza: True, but in this case you can use settimeout as well to wait just for a little amount of time. Nevertheless you have make a query otherwise you will never know whether there is a useable connection. Good luck! – Blauharley Jan 23 '17 at 12:18

0 Answers0