Android的事件,互联网连接状态变化 [英] Android event for internet connectivity state change

查看:96
本文介绍了Android的事件,互联网连接状态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个应用程序,其中一个用户上传信息和文件到我的服务器上有点频繁。这是通过一个专用的上载服务完成在新主题。

I am making an app where a user is uploading information and files to my server on a somewhat frequent basis. This is done in new threads through a dedicated uploader service.

我知道,从这个线程

<一个href="http://stackoverflow.com/questions/4238921/android-detect-whether-there-is-an-internet-connection-available">Android - 检测是否有互联网连接可用

您可以检查是否有网络连接比较容易。您还可以得到socketTimeoutExceptions检测网络连接问题。所有这一切都很好,并让我缓存我上传的很轻松地连接时无论出于何种原因没有工作。

that you can check if there is an internet connection relatively easily. You can also get socketTimeoutExceptions to detect internet connectivity issues. All that is well and good, and lets me cache my uploads easily enough when the connection didn't work for whatever reason.

我的问题,虽然是我怎么知道什么时候重新尝试上传?是否有触发的事件在连接恢复的时候?还是我坚持做一个新的线程睡眠,然后检查互联网连接每30秒什么的?

My question though is how do I know when to reattempt the upload? Is there an event triggered when the connection is restored? Or am I stuck making a new thread that sleeps and then checks internet connectivity every 30 seconds or something?

任何想法,将AP preciated!

Any ideas would be appreciated!

Avtar

推荐答案

有一个广播接收器连接的变化。请参见这里

There's a broadcast receiver for connectivity changes. See here

这篇关于Android的事件,互联网连接状态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆