在程序代码中对wifi网络发生变化情况进行处理

发布时间:2020-08-05 12:52:06 作者:truesea
来源:网络 阅读:352

当wifi功能被关闭时,在Log中看到以下和wifi状态改变有关的日志:

11-04 11:09:34.559: E/WifiService(185): Handle MESSAGE_DISABLE_WIFI.
11-04 11:09:34.569: D/DATA(287): [DCT(0) ] intent received :android.net.wifi.WIFI_STATE_CHANGED
11-04 11:09:34.569: D/StatusBarPolicy(254): updateWifi: android.net.wifi.WIFI_STATE_CHANGED : wifi state: 0 supplicant connected: false
11-04 11:09:34.579: I/wpa_supplicant(8310): CTRL-EVENT-TERMINATING - signal 15 received
11-04 11:09:34.579: V/WifiMonitor(185): Event [CTRL-EVENT-TERMINATING - signal 15 received]
11-04 11:09:34.579: V/WifiStateTracker(185): handleMessage(): msg.what= 2

在当前程序中没有对wifi断开进行处理,所以出现以下异常:

11-04 11:09:35.889: E/DownThread(7389): Connection timed out
11-04 11:09:35.889: E/DownThread(7389): java.net.SocketException: Connection timed out
11-04 11:09:35.889: E/DownThread(7389):     at org.apache.harmony.luni.platform.OSNetworkSystem.read(Native Method)
11-04 11:09:35.889: E/DownThread(7389):     at dalvik.system.BlockGuard$WrappedNetworkSystem.read(BlockGuard.java:273)
11-04 11:09:35.889: E/DownThread(7389):     at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:458)
11-04 11:09:35.889: E/DownThread(7389):     at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
11-04 11:09:35.889: E/DownThread(7389):     at java.io.BufferedInputStream.read(BufferedInputStream.java:319)
11-04 11:09:35.889: E/DownThread(7389):     at org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream.read(FixedLengthInputStream.java:44)
11-04 11:09:35.889: E/DownThread(7389):     at java.io.BufferedInputStream.read(BufferedInputStream.java:319)
11-04 11:09:35.889: E/DownThread(7389):     at java.io.FilterInputStream.read(FilterInputStream.java:133)
11-04 11:09:35.889: E/DownThread(7389):     at com.tvie.ivideo.download.logic.DownThread.run(DownThread.java:65)

出现异常的代码是InputStream的read方法。

while ((len = is.read(buffer)) != -1 && running) {

read方法的声明表现会抛出IOException。

int java.io.InputStream.read(byte[] buffer) throws IOException


推荐阅读:
  1. 怎么在C++中对异常进行处理
  2. 怎么在Spring Batch中对框架进行处理

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

程序代码 wifi网络发生变化 进行处理

上一篇:set,map相关操作

下一篇:spring-boot-plus后台快速开发框架1.0.0.RELEASE发布了

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》