4

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" />
Yesudass Moses
  • 1,841
  • 3
  • 27
  • 63

3 Answers3

3

<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.

Sagar
  • 23,903
  • 4
  • 62
  • 62
3

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.

P.S: SUPPLICANT_CONNECTION_CHANGE_ACTION is deprecated from API level P

Community
  • 1
  • 1
Masoom Badi
  • 986
  • 9
  • 18
  • How can I get the extra NetworkInfo object. What I want is to know which SSID is disconnected – Yesudass Moses May 15 '18 at 06:28
  • you mean, you need to know when the device get connected or disconnected from network state(net is available or not)? – Masoom Badi May 15 '18 at 06:35
  • I want to start an activity when a particular SSID is disconnected. I tried NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); in broadcastreceiver. networkInfo object returns – Yesudass Moses May 15 '18 at 06:42
  • tyy like this? cause EXTRA_NETWORK_INFO is deprecated. `ConnectivityManager connectivityManager = (ConnectivityManager) myContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();` – Masoom Badi May 15 '18 at 06:53
  • that is because no default network is currently active – Masoom Badi May 15 '18 at 07:13
  • I don't know why they removed EXTRA_NETWORK_INFO. That was giving me all states like connected, connecting, disconnected, authenticating.. – Yesudass Moses May 15 '18 at 07:30
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/171052/discussion-between-sam-and-yesudass-moses). – Masoom Badi May 15 '18 at 07:50
0

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

Venki WAR
  • 1,997
  • 4
  • 25
  • 38