当电池电量低于 20% 但应用程序在单击时崩溃时,我尝试使用此方法在单击切换按钮时禁用 wifi:
public void getRisparmio(View view, Intent intent) {
// is the toggle on?
boolean on = ((ToggleButton) view).isChecked();
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
WifiManager wifiManager;
if (on && level<20) {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
} else {
wifiManager(WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
}
}
有任何想法吗?