如何为URLConnection.getInputStream()设置Timeout?

时间:2015-02-10 01:49:45

标签: android

我正在使用URLConnection.getInputStream()进行应用程序的更新检查。

这是我的代码:

java.net.URL url = new URL("http://somewhere.com/checkUpdate.html");
URLConnection conn = url.openConnection();
conn.setConnectTimeOut(3000);

if(conn!=null){
    conn.setUseCaches(false);
    BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); // app stopped here

    doSomeThing();


}

此代码在WiFi(正常状态),LTE中运行良好。 但是WiFi的状态是不稳定的,应用程序在conn.getInputStream()停止。

然后,我想为conn.getInputStream()设置超时。 我怎样才能设置超时?

或者,请告诉我任何解决方案而不是设置超时。 感谢。

对不起,简短的英文..

0 个答案:

没有答案
相关问题