Android 知道google glass是否可以在没有等待时间的情况下连接互联网

Android 知道google glass是否可以在没有等待时间的情况下连接互联网,android,google-glass,google-gdk,Android,Google Glass,Google Gdk,我需要知道我的杯子是否可以连接互联网 我尝试过使用这个解决方案 在XE 17.1中,我的工作正常,但当我将我的Glass更新为XE 18.1时,我的工作正常,但我需要等到时间结束后才能知道Glass没有互联网连接。在XE17.1中,这不会发生。如果没有连接性,则会在没有等待时间的情况下抛出异常 你有没有想过不用等待时间就可以了解互联网连接 谢谢 您是否尝试过使用InetAddress.getByName(“google.com”).isReachable()测试连接性?它可能不如TCP上的GET

我需要知道我的杯子是否可以连接互联网

我尝试过使用这个解决方案

在XE 17.1中,我的工作正常,但当我将我的Glass更新为XE 18.1时,我的工作正常,但我需要等到时间结束后才能知道Glass没有互联网连接。在XE17.1中,这不会发生。如果没有连接性,则会在没有等待时间的情况下抛出异常

你有没有想过不用等待时间就可以了解互联网连接


谢谢

您是否尝试过使用
InetAddress.getByName(“google.com”).isReachable()测试连接性?它可能不如TCP上的GET请求可靠,但我已经在实践中看到了这一点。

您好!是的,我试过,但当我使用
InetAddress.getByName(“google.com”).isReachable()
时,有时它对我不起作用,当我没有互联网连接时,我得到了
true
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");
}