Android check WIFI status (disconnected or user changed WIFI)

I is there a way to Flag if a WIFI connection got disconnected/ dropped off OR if the user actually changed the WIFI network ?

I need my app to do :
Connect to a WIFI XYZ, if XYZ get disconnect (FLAG 1) or dropped off Then reconnect to XYZ.
But is the user change to another wifi BTOpen (FLAG 2) then allow the connect and Stop my service.
If user connect to XYZ again then start the loop again.

hmmmm. This is going to be a bit of a tricky scenario unless the user changes wifi connections in your app. Because you can register for WifiStateChanged receivers, but it will just report on the current state.

You can start by creating to broadcast receivers and log out when the devices gets those broadcasts and try some clever logic around it

Use this to trigger your service everytime the wifi state changes:

<receiver android:name=".receivers.WifiStateChangeReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        </intent-filter>
</receiver>

And you can use this to get the wifi scan results:

 <receiver android:name=".receivers.WifiScanReceiver" android:enabled="true">
        <intent-filter>
            <action android:name="android.net.wifi.SCAN_RESULTS" />
        </intent-filter>
 </receiver>

Then once you have the scan results and the network you want to connect to is in the list, you can connect to it.

I hope this helps

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.