This sample demonstrates how to use the ConnectivityManager
to determine if the device has an active network connection, and if so, retrieve the connection type.
ConnetivityManager
Class OverView
Class that answers queries about the state of network connectivity. It also notifies applications when network connectivity changes. Get an instance of this class by calling Context.getSystemService(Context.CONNECTIVITY_SERVICE)
.
The primary responsibilities of this class are to:
- Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)
- Send broadcast intents when network connectivity changes
- Attempt to "fail over" to another network when connectivity to a network is lost
- Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks
- Provide an API that allows applications to request and select networks for their data traffic
这个 Sample 展示 怎么样使用ConnectivityManager去确定是否设备有一个有效的网络连接,并且如果有一个,返回连接类型。
连接管理类。
类概述
该类回答查询网络连接状态,当网络连接改变时,它也会通知应用程序。通过调用Context.getSystemService(Context.CONNECTIVITY_SERVICE)返回一个实例。
这个类的主要负责:
1.显示网络连接(Wi-Fi, GPRS, UMTS, etc.)
2.当网络连接改变是(发送)广播intents
3.当网络丢失时,试图去(连接)娶她网络
4.提供一个API去允许应用程序查询可用的网络的oarse-grained or fine-grained 状态(oarse-grained or fine-grained 可能表示网络信号的好、坏的吧)
5.提供一个API去允许应用为了他们的数据传输查询和选择一个网络。