I am making a small project in which i am setting the wifi to disable if the battery is less than 30%. But if the user enables the wifi again i want it must not be disable again. I did this whole work in service class The code i used is... Kindly give any suggestion. Your suggestions are very valuable for me..
public class BatteryService extends Service
boolean checkwifi;
WifiManager mainWifi;
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
checkwifi = true;
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
if (level <= 30 && !isCharging) {
tts.speak(" Battery LOw Connect Phone to Charger",
TextToSpeech.QUEUE_FLUSH, null);
if (checkwifi) {
mainWifi.setWifiEnabled(false);
bt.disable();
closemobiledata();
checkwifi = false;
}
}
Update 1:
I found the problem, the problem is service is starting again and again What to do so that service must not start again and again
public class BatteryService extends Service
boolean checkwifi;
WifiManager mainWifi;
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(getApplicationContext(), "Service created", Toast.LENGTH_SHORT).show();
checkwifi = true;
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
if (level <= 30 && !isCharging) {
tts.speak(" Battery LOw Connect Phone to Charger",
TextToSpeech.QUEUE_FLUSH, null);
if (checkwifi) {
mainWifi.setWifiEnabled(false);
bt.disable();
closemobiledata();
checkwifi = false;
}
}