Cordova GetNetwork Type - not finding network


Ryan Sytsma

The below code does not seem to be working. This depends on the Cordova Network plug in right? The only value I get back is false.

Am I using this correctly?



DecSoft

Hello Ryan,

You are right, that action relies in the Cordova Network plugin. And yes... in principle, must work. Are you executing that code after the app "Ready" event? I asume that yes (that is mandatory, since Cordova stuff is available in that or after that event). Can you please try with an "Alert" that just show the value of the variable that you pass to the action? So we can discard some possible mistake in the condition.



Ryan Sytsma

I have tried to test the GetNetworkType function using the Android Studio Emulator but it always returns false no mater what I set the network parameters to.

I am going to order a tablet today to test on a real device



DecSoft

Hello Ryan,

Humm... probably the plugin can't work in the emulator. I just test the action and the plugin here in an Android device and works as expected, so, probably you can see it also working in a real device.



Ryan Sytsma

It will be a more complete testing environment anyway. I will post back on this thread after I run it on the Android tablet.



DecSoft

Hello Ryan,

Yes; a real device is probably the best way to debug things that cannot be debugged in the browser(s). Not only more faster, but also better, because, as we can see here, the emulator don't support certain kind of stuff, that the device support.

Remember to install the Google USB drivers (if needed) and just connect the device to the computer. Then use the "Run" BAT file and the app must be automatically launched in the device after has been successfully compiled.



Ryan Sytsma

I got my test Android tablet today, and I ran the below code with both the wifi on and off. Running this test is always returning "false".

I built the apk and copied it over to the tablet and installed it on the tablet. FYI



DecSoft

Hello Ryan,

I think the problem is in the condition. You must use "&&" (AND) instead "||" (OR), because, in other case, we probably always fall in that condition and then the "hasNetwork" variable become false. So the condition must look something like:

About to copy the APK file and then install the app in the device... you can avoid that if properly connect the device via USB, and then use the "Run" BAT file.



Ryan Sytsma

Thanks David. I will give the && a try.

I connected the device via usb and I can browse the device using windows explorer, but when I use the Run BAT file, I get a message in the command window that it cannot find a device and so it tries to launch emulator. I will try installing the Google USB drivers .



DecSoft

Hello Ryan,

Yes; the USB drivers can do the trick. Anyway, try it, that is, look for it, because the debug process is faster in this way.



DecSoft

Hello Ryan,

Be sure also that you has enable USB debugging in your device.



Ryan Sytsma
Changing the IfEx to use && worked and now I am getting the proper feedback. Thank you sir!

DecSoft

No problem, Ryan! :-)


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.