Search code examples
javaandroidgpswifi

Toggling state of Wifi in Android device


I have to make an app in which I need to display the status of the WiFi on a RadioGroup (Either its "on" or "off"). I want the default behavior for the application to show the status of the Wifi when the user clicks the SettingsPage. The RadioGroup must check the status of the Wifi and display it accordingly("on" or "off"). I must also be able to toggle the states of the Wifi.

I hope the images below can make my question clear.

Thanks for your time.

enter image description here


Solution

  • Check this question: Android: How to Enable/Disable Wifi or Internet Connection Programmatically

    And make sure the radio button is selected if the wifi is on otherwise make radio button as not selected.

    More info about checking wifi status:

    WifiManager wifi = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
    boolean b=wifi.isWifiEnabled();