0 down vote favorite 1 share [g+] share [fb] share [tw]
I'm stuck with a little problem here ! I want my app to do something, but only when the battery is at 10%. My app doesn't watch constantly the battery level it just wait for a LOW_BATTERY intent. It works if i don't specify a level but it works 3 times. (15%, 10%, and 5%) I only want it to do something at 10%. Here is my code : public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(ACTION_BATTERY_LOW)) { int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); int percent = (level*100)/scale; if(percent == 10) { //Do Something } } } It doesn't work, any ideas ? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en