【发布时间】:2013-02-14 10:07:55
【问题描述】:
我尝试从移动设备下载文件。手机是通过wifi连接的,有时候手机换个位置,就连接到另一个wifi。对于下载,我使用:
final URLConnection ucon = url.openConnection();
ucon.setReadTimeout(10000);
ucon.setConnectTimeout(10000);
final InputStream inputStream = ucon.getInputStream();
final BufferedInputStream bis = new BufferedInputStream(inputStream);
在 bis.available() 和 bis.read() 之后获取数据直到字节数 > ucon.getContentLength()。
当 wifi 连接发生变化时,我预计会出现 (IO)Exception(或至少是 TimeoutException),但什么都没有。
在另一个类中,我检查了网络连接(使用广播接收器),我看到事件断开/连接正常。所以,我可以使用广播接收器停止并重新开始下载,但我认为这不是最好的方法。
你有什么想法在这种情况下获得例外吗?
谢谢。
【问题讨论】:
标签: android download inputstream urlconnection timeoutexception