I'm writing an application that when the battery level is less of 10% the wifi connection (if activate) will disable. This is what i want but not what i am able to do :). I've created a toggle and when pressed the wifi stops and vice versa if press again the wifi turns on in this way:
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(false);
} else {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(tru);
}
}
in this way i get the battery level:
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
what i want is something like
public void getRisparmio(View view) {
// is the toggle on?
boolean on = ((ToggleButton) view).isChecked();
WifiManager wifiManager;
if (on) {
if (level < 10){
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
}
} else {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
}
}
Is it possible? Thanks