简体   繁体   中英

android.net.wifi.STATE_CHANGE or android.net.wifi.supplicant.CONNECTION_CHANGE

In android broadcasts, what's the difference between

 <action android:name="android.net.wifi.STATE_CHANGE"/>

and

 <action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />

<action android:name="android.net.wifi.STATE_CHANGE"/>

Broadcast intent action indicating that the state of Wi-Fi connectivity has changed.

<action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />

Broadcast intent action indicating that a connection to the supplicant has been established (and it is now possible to perform Wi-Fi operations) or the connection to the supplicant has been lost.

Note:

This constant was deprecated in API level P. This is no longer supported.

STATE_CHANGE : Broadcast intent action indicating that the state of Wi-Fi connectivity has changed. An extra provides the new state in the form of a NetworkInfo object.

This is lookup key for an int that indicates whether Wi-Fi is enabled, disabled, enabling, disabling, or unknown.

CONNECTION_CHANGE : Broadcast intent action indicating that a connection to the supplicant has been established (and it is now possible to perform Wi-Fi operations) or the connection to the supplicant has been lost. One extra provides the connection state as a boolean, where true means CONNECTED.

This is a lookup key for a boolean that indicates whether a connection to the supplicant daemon has been gained or lost. {@code true} means a connection now exists.

PS: SUPPLICANT_CONNECTION_CHANGE_ACTION is deprecated from API level P

The android.net.wifi.supplicant.CONNECTION_CHANGE action was sends a broadcast when the network is connected, but usually before the device has an IP address, so we needed the android.net.wifi.STATE_CHANGE action for that.

The android.net.wifi.STATE_CHANGE action receives a broadcast on disconnect only if the device is disconnecting from a network, but wifi is still enabled (when hotspot goes out of range, for example)

For more information see android developers officialsite https://developer.android.com/reference/android/net/wifi/WifiManager#SUPPLICANT_CONNECTION_CHANGE_ACTION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM