/**
* Broadcast intent action indicating that Wi-Fi has been enabled, disabled,
* enabling, disabling, or unknown. One extra provides this state as an int.
* Another extra provides the previous state, if available.
*
* @see #EXTRA_WIFI_STATE
* @see #EXTRA_PREVIOUS_WIFI_STATE
*/
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
public static final String WIFI_STATE_CHANGED_ACTION =
"android.net.wifi.WIFI_STATE_CHANGED";
// 自定义个broadcast 在广播接收器Broadcast中判断,
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
//这个监听wifi的打开与关闭,与wifi的连接无关 int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0); LogTag.showTAG_e("WIFI状态", "wifiState"+wifiState); switch (wifiState) { case WifiManager.WIFI_STATE_DISABLED: break; case WifiManager.WIFI_STATE_DISABLING: break; // } }
各个状态的值如下:
/**
* Wi-Fi is currently being disabled. The state will change to {
@link #WIFI_STATE_DISABLED} if
* it finishes successfully.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int WIFI_STATE_DISABLING = 0;
/**
* Wi-Fi is disabled.
*
* @see #WIFI_STATE_CHANGED_ACTION
* @see #getWifiState()
*/
public static final int <