Android Sample 之 BasicNetworking

来源:互联网 发布:黎巴嫩真主党 知乎 编辑:程序博客网 时间:2024/06/05 02:26

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:

  1. Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)
  2. Send broadcast intents when network connectivity changes
  3. Attempt to "fail over" to another network when connectivity to a network is lost
  4. Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks
  5. 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去允许应用为了他们的数据传输查询和选择一个网络。

0 0
原创粉丝点击