ConnectivityManager

这个类是用来查询设备的网络连接状态的。当网络连接发生变化时,也会去提醒程序。通过Context.getSystemService(Context.CONNECTIVITY_SERVICE)获取实例

这个类有以下几个职责:

1 管理网络连接(wifi,GPRS,UMTS,etc

2 网络发生变化时发送广播

3当网络失去连接时,尝试”fail over“到另一个网络连接

4Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks

5提供用户查询和选择数据交换网络方式的API


public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED

This constant was deprecated in API level 16.
As of ICE_CREAM_SANDWICH, availability of background data depends on several combined factors, and this broadcast is no longer sent. Instead, when background data is unavailable, getActiveNetworkInfo() will now appear disconnected. During first boot after a platform upgrade, this broadcast will be sent once if getBackgroundDataSetting() was false before the upgrade.

Broadcast Action: The setting for background data usage has changed values. Use getBackgroundDataSetting() to get the current value.

If an application uses the network in the background, it should listen for this broadcast and stop using the background data if the value isfalse.

Constant Value: "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"

public static final String CONNECTIVITY_ACTION
Added in  API level 1

A change in network connectivity has occurred. A default connection has either been established or lost. The NetworkInfo for the affected network is sent as an extra; it should be consulted to see what kind of connectivity event occurred.

If this is a connection that was the result of failing over from a disconnected network, then the FAILOVER_CONNECTION boolean extra is set to true.

For a loss of connectivity, if the connectivity manager is attempting to connect (or has already connected) to another network, the NetworkInfo for the new network is also passed as an extra. This lets any receivers of the broadcast know that they should not necessarily tell the user that no data traffic will be possible. Instead, the receiver should expect another broadcast soon, indicating either that the failover attempt succeeded (and so there is still overall data connectivity), or that the failover attempt failed, meaning that all connectivity has been lost.

For a disconnect event, the boolean extra EXTRA_NO_CONNECTIVITY is set to true if there are no connected networks at all.

Constant Value: "android.net.conn.CONNECTIVITY_CHANGE"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值