本文介绍了如何监控在Android的网络连接状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个是从服务器下载的文件服务。我警告用户只下载文件通过无线网络下载开始前。
I have a Service that is downloading a file from a server. I warn the user to only download the file over Wireless LAN before the download starts.
我的问题是,我的下载卡,如果我失去了网络连接。有没有办法来监听变化的网络连接,或者如果它完全失去了什么?
My problem is that my download gets stuck if I loose the network connection. Is there a way to listen for changes in network connection or if it is lost entirely?
推荐答案倾听CONNECTIVITY_ACTION
这看起来不错sample code 。这里是一个片段:
This looks like good sample code. Here is a snippet:
BroadcastReceiver networkStateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.w("Network Listener", "Network Type Changed"); } }; IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(networkStateReceiver, filter);更多推荐
如何监控在Android的网络连接状态?
发布评论