0

I need to know if my glass has internet connectivity.

I have tried to use this solution How to check if Google Glass is connected to internet using GDK

public static void isNetworkAvailable(Context context){
HttpGet httpGet = new HttpGet("http://www.google.com");
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
try{
    Log.d(TAG, "Checking network connection...");
    httpClient.execute(httpGet);
    Log.d(TAG, "Connection OK");
    return;
}
catch(ClientProtocolException e){
    e.printStackTrace();
}
catch(IOException e){
    e.printStackTrace();
}

Log.d(TAG, "Connection unavailable");
}

It's work ok for my in XE 17.1 but when i have updated my Glass to XE 18.1 it's work but i need to wait until TIME_OUT to know Glass have not internet connectivity. In XE 17.1 it's not happen. If i hadn't connectivity, a exception was threw without waiting TIME_OUT.

Any idea for know internet connectivity without waiting Time out?

Thanks!

Community
  • 1
  • 1
Bae
  • 892
  • 3
  • 12
  • 26

1 Answers1

0

Have you tried using InetAddress.getByName("google.com").isReachable(<timeout>) for testing connectivity? It might not be as reliable as a GET request over TCP, but I've seen this work pretty well in practice.

Brandon Wuest
  • 206
  • 1
  • 2
  • Hi! Yes, i tried but when i used ``InetAddress.getByName("google.com").isReachable()`` Sometimes it isn't worked for me and i get ``true`` when i hadn't Internet connectivity >. – Bae Aug 26 '14 at 09:56