Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap - navigator.connection.type not defined

I am trying to check for an established network connection through the phonegap/cordova API, but alas, it is not working.

I added the plugin as explained on the cordova documentation, and phonegap local plugin list gives [phonegap] org.apache.cordova.network-information.

However, simply calling

document.addEventListener("deviceready", function () {
  alert(Object.keys(navigator.connection));
}, false);

results on my phone (Android 4.0.4) always returning 0 and running on an emulator with Android 4.4.2 logs into LogCat that navigator.connection is undefined. In fact, on both machines alert(Object.keys(navigator)); never shows the connection key.

Any solution?

Phonegap with Cordova 3.3.0

like image 538
alex Avatar asked Oct 20 '22 16:10

alex


1 Answers

When you install the plugin it copies files to www/plugins and updates android.json

then when you build the project, the build copies the java to platforms/android/src/... and the js files to platforms\android\assets\www\plugins (and does any customisation defined in plugin.xml)

At multiple occasions I saw android.json not correctly updated and javascript files not copied. Removing and re-installing plugins solved the problem for me.

If you did not perform manual customisations to the platforms/android folder, I think the easiest way to clean your project would be to empty the /plugins folder and the platforms folder and then re-install all the plugins you need.

like image 60
QuickFix Avatar answered Oct 23 '22 19:10

QuickFix