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

查看:138
本文介绍了互联网连接状态更改的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.

我从这个线程知道

Detect whether there is an Internet connection available on Android

你可以检查互联网连接是否比较容易。您还可以获取socketTimeoutExceptions来检测Internet连接问题。所有这一切都很好,让我可以轻松地缓存我的上传,当连接因为任何原因不起作用。

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?

任何想法都将不胜感激!

Any ideas would be appreciated!

Avtar

推荐答案

有连接更改的广播接收器。请参阅此处

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

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

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