How to make plugin network working

Hello

I am contacting you because I am not able to make the plugin network working

export const NETWORK_ALLOWING_CONNECTION = ["ethernet", "wifi", "2g", "3g", "4g"]

      ...
      ...

  Network.onDisconnect().subscribe(() => {
		  console.log('Network disconnected'); 
		  this.isNetworkAvailable = false;
		})

		// check for connection
		Network.onConnect().subscribe(() => {
		  console.log('network connected!'); 

		  // wait a bit before having the type
		  this.interval = setInterval(() => {
			this.analyzeNetworkType();
		  }, 1000);
		})

		// check on change on the status
		Network.onchange().subscribe(() => {
		  this.analyzeNetworkType();
		});
		
		
		...
                    ...
		
		private analyzeNetworkType(){
		  if (!Network.type) {
			console.log('No network type found');
		  } else if(NETWORK_ALLOWING_CONNECTION.indexOf(Network.type) != -1){
			console.log("Network found: " + Network.type);
			this.isNetworkAvailable = true;
			if(this.interval){
				clearInterval(this.interval);
			}
		  } else{
			if(this.interval){
				clearInterval(this.interval);
			}
		  }
		}

But I never enter in any of the subscribe. I added as well an

   err => console.log(err)

But nothing…

I am trying on LG G4 with android 6.0

Thanks in advance

Are you certain that you actually installed the plugin?

And imported/provided it into your app.module and also imported it into the specific template?

Failing to do that should generate errors. Doing all that yet failing to install the plugin itself will behave as OP described: silently not having handlers called. Not that I ever did something so silly so as to have had firsthand experience of this, you understand.

1 Like

Ah hahaha that’s very true. I didn’t expect anything less from you. @speedflyer If you’re not certain whether the plugin is installed or not, run cordova plugin list to get all the plugins installed in your current directory.

I am using ionic Native 2.8.0
With this version all the plugin must be used in a static way.
I am currently using barecode scanner, camera, contacts, inapp browser, globalization and geolocalisation which are working pretty well with static methods.
I added the plugin with the same command as the other :
ionic plugin add
I will check with command you said to test.

I would highly recommend upgrading to ionic-native 3. It will significantly shrink your app binary size and improve startup speed.

Here is the list of plugin:

cordova-plugin-camera 2.4.0 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.6 "Console"
cordova-plugin-contacts 2.3.0 "Contacts"
cordova-plugin-device 1.1.5 "Device"
cordova-plugin-geolocation 2.4.2 "Geolocation"
cordova-plugin-globalization 1.0.6 "Globalization"
cordova-plugin-inappbrowser 1.7.0 "InAppBrowser"
cordova-plugin-inapppurchase 1.1.0 "In App Purchase"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-splashscreen 4.0.2 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-plugin-x-socialsharing 5.1.6 "SocialSharing"
cordova-sqlite-storage 2.0.2 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-barcodescanner 6.0.5 "BarcodeScanner"

We can clearly see that the plugin is there :frowning:

Concerning ionic 3 it is in my plan. However it is not a direct plan because the startup time is acceptable in my app and I have a huge gap.

Okay and did you try to clean and rebuild your platform already? (yes you should upgrade to ionic Native 3.x as soon as possible btw)

2 Likes

For what it’s worth, I think faster starter times always give a better user experience. Don’t settle for acceptable, strive for the best possible :wink: You mention a huge gap, between what exactly?

1 Like

I am in 2.1.0 of ionic angular :slight_smile:
I will try to clean and rebuild.
I will let you know

Concerning the migration I will try during my holidays :slight_smile:

So I did a remove then re-add
Ionic run android with and without prod :frowning:
Still never enter…
I will check in debug if I enter in cordova code

After reinstalling everything it is working.
It is like an internet box sometime we need to unplug and replug :slight_smile:

Thx