Ionic Cordova Network Plugin Not detecting a Network Connection

I have successfully installed cordova network plugin and no errors so far from the code side.

When I use ionic serve to get the app to run on my browser, it detects my wifi and the plugin recognizes a connection, and if i disable wifi on my computer, it again recognizes that there is no internet connection.

The problem now comes when I install the app onto an android phone after building. I even have Bluestacks on my computer but the app does not get the network from there too. Has anyone run into this problem? How did you go through it?

I do not think it is an issue with my code, so I am not posting code, unless someone will need it for clarification.

I hope someone is able to help.

I created a provider and used in the component …

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import {Platform,  AlertController} from 'ionic-angular';
import 'rxjs/add/operator/map';
//
import { Network } from 'ionic-native';

declare var navigator: any;

@Injectable()
export class NetworkCheck {

  constructor(private http: Http , private alertCtrl: AlertController) {
  }
  
  checkNetworkWithWindow (){
    return window.navigator.onLine;
  }
  showAlert() {
    let alert = this.alertCtrl.create({
      title: 'No Network',
      subTitle: 'Please turn on your network connection to use the service !',
      buttons: ['OK']
    })
    alert.present();
  }
}

This approach bypass the native plugin and relies on the window object

1 Like