android - Phonegap check internet connection -
how can check internet connection in cordova 3.0 build? because tried
function ondeviceready(){ checkconnection(); alert(navigator.connection.type); }
but returns 0.
i heard jquery mobile don't know how use because tried
function checkconnection(){ alert(navigator.online);}
with jquery mobile library loaded returns true.
this happening on smartphone , on avd too.
can me?
you can check connection this:
function checkconnection() { if( !navigator.network ) { // set parent windows navigator network object child window navigator.network = window.top.navigator.network; } // return type of connection found return ( (navigator.network.connection.type === "none" || navigator.network.connection.type === null || navigator.network.connection.type === "unknown" ) ? false : true ); }
returns true connection , false no connectivity.
in android manifest, use following permission:
<uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.internet" />
edit: handles windows in iframes well. added permission.
Comments
Post a Comment