Reputation: 1359
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.
Upvotes: 1
Views: 939
Reputation: 596
To Enable WiFi:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
Note: To access with WiFi state, we have to add following permissions inside the AndroidManifest.xml file:
android.permission.ACCESS_WIFI_STATE
android.permission.UPDATE_DEVICE_STATS
android.permission.CHANGE_WIFI_STATE
Upvotes: 0
Reputation: 128428
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();
Upvotes: 4