Tuesday, 15 July 2014

android - java.net.UnknownHostException: Unable to resolve host "www.google.com" -



android - java.net.UnknownHostException: Unable to resolve host "www.google.com" -

i'm trying observe if there net connection , websites reachable. have broadcast receiver runs next method on receive:

public boolean hasinternetnow() { thread checkinternet = new thread(new runnable() { @override public void run() { seek { seek { connectivitymanager cm = (connectivitymanager) mycontext.getsystemservice(context.connectivity_service); if (cm.getactivenetworkinfo().isconnectedorconnecting()) { url url = new url("http://www.google.com"); httpurlconnection urlc = (httpurlconnection) url .openconnection(); urlc.setrequestproperty("user-agent", "test"); urlc.setrequestproperty("connection", "close"); urlc.setconnecttimeout(1000); // mtimeout in seconds urlc.connect(); if (urlc.getresponsecode() == 200) { setinternetdetected(true); } else { setinternetdetected(false); } } } grab (ioexception e) { e.printstacktrace(); setinternetdetected(false); } grab (nullpointerexception e){ e.printstacktrace(); setinternetdetected(false); } } grab (exception e) { e.getlocalizedmessage(); setinternetdetected(false); } } }); checkinternet.start(); homecoming internetdetected(); }

while connected wifi , google reachable through net app, next error:

10-15 07:50:46.656: w/system.err(24203): java.net.unknownhostexception: unable resolve host "www.google.com": no address associated hostname 10-15 07:50:46.656: w/system.err(24203): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:426) 10-15 07:50:46.656: w/system.err(24203): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:242) 10-15 07:50:46.656: w/system.err(24203): @ java.net.inetaddress.getallbyname(inetaddress.java:220) 10-15 07:50:46.656: w/system.err(24203): @ libcore.net.http.httpconnection.<init>(httpconnection.java:71) 10-15 07:50:46.656: w/system.err(24203): @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 10-15 07:50:46.656: w/system.err(24203): @ libcore.net.http.httpconnection$address.connect(httpconnection.java:351) 10-15 07:50:46.656: w/system.err(24203): @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:86) 10-15 07:50:46.656: w/system.err(24203): @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 10-15 07:50:46.666: w/system.err(24203): @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:308) 10-15 07:50:46.666: w/system.err(24203): @ libcore.net.http.httpengine.connect(httpengine.java:303) 10-15 07:50:46.666: w/system.err(24203): @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:282) 10-15 07:50:46.666: w/system.err(24203): @ libcore.net.http.httpengine.sendrequest(httpengine.java:232) 10-15 07:50:46.666: w/system.err(24203): @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:80) 10-15 07:50:46.666: w/system.err(24203): @ com.appiclife.ezcallcallingcardvoiptool.devicedata$1.run(devicedata.java:110) 10-15 07:50:46.666: w/system.err(24203): @ java.lang.thread.run(thread.java:856) 10-15 07:50:46.666: w/system.err(24203): caused by: libcore.io.gaiexception: getaddrinfo failed: eai_nodata (no address associated hostname) 10-15 07:50:46.666: w/system.err(24203): @ libcore.io.posix.getaddrinfo(native method) 10-15 07:50:46.666: w/system.err(24203): @ libcore.io.forwardingos.getaddrinfo(forwardingos.java:55) 10-15 07:50:46.666: w/system.err(24203): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:411)

what missing here?

this method same:

public boolean isinternetavailable() { seek { inetaddress ipaddr = inetaddress.getbyname("google.com"); //you can replace name if (ipaddr.equals("")) { homecoming false; } else { homecoming true; } } grab (exception e) { homecoming false; } }

java android connectivity httpconnection unknown-host

No comments:

Post a Comment