In my application i have a toggle button that needs to activate or disable the wifi.
public void getRisparmio(View view) {
// is the toggle on?
boolean on = ((ToggleButton) view).isChecked();
WifiManager wifiManager;
if (on) {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
} else {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
}
}
Now the problem is: if the wifi is already activated and I launch the app, the toggle button should be pressed/activated. Actually doesn't go and the toggle always resume its state on off. I think i can check the state onResume()
but i don't know how and i don't know if i have to add something in the onCreate()
method too.
How can i do to check the state? Thanks