Access network availability state android -
i developing application want access whether there internet connectivity or not. can access network state using
private boolean isnetworkavailable() { connectivitymanager connectivitymanager = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo activenetworkinfo = connectivitymanager.getactivenetworkinfo(); return activenetworkinfo != null && activenetworkinfo.isconnected(); } but returns whether mobile connected internet or not. want know if there internet availability after connecting. like, may server down or internet not available. please let me know how accomplish this!
try this,
url url = new url("your url"); urlconnection conexion = url.openconnection(); conexion.setconnecttimeout(10000); // don't forget put time limit conexion.connect(); after timeout (10 secs above mentioned example), through time out exception. can use check whether internet access available or not.
Comments
Post a Comment