60

Is there an Android API for stop charging even though physically the charging is on?

citizen conn
  • 15,300
  • 3
  • 58
  • 80
daniel
  • 601
  • 1
  • 5
  • 3
  • 4
    Very valid question, as it would be nice to prevent charging past 70% to reduce battery aging. However the answer is quite simple: there's no API to achieve this :( – 3c71 Oct 06 '13 at 05:46
  • http://stackoverflow.com/questions/15993635/how-to-stop-the-phone-from-charging-via-usb-programmatically suggests it is possible on rooted devices? – Tom Jan 10 '14 at 12:19

9 Answers9

15

Reading previous answers, it looks like there's no way to do this exclusively in software. However, it should be relatively easy to do it with a little hardware help - i.e. by using any Bluetooth- or WiFi-enabled smart electrical switch with open API. The phone could then switch the charger on or off programmatically whenever it feels like it.

Kibber
  • 267
  • 2
  • 5
  • 1
    Perfectly good solution. No idea why someone downvoted you. See [How to automatically stop charging your phone](http://www.adamcolson.com/blog/10-tech/38-how-to-automatically-stop-charging-your-phone). – Paul Jurczak Oct 10 '16 at 02:43
  • Well, strictly speaking, it does answer a different question than what was asked. But since the answer to the question as asked is "No", what I suggested is better than nothing. As for the post you linked - that's pretty much what I ended up doing, except I got a different device with two switchable outlets instead of just one and it only cost $27 on Amazon (hint - it has the word "Genius" in the name). – Kibber Oct 11 '16 at 20:54
  • 2
    this answer is plain **WRONG**. you can do this from software via the /sys/class/power_supply/battery/device/charge interface, but only root can write to it on most systems – hanshenrik Sep 23 '19 at 15:09
  • 1
    @kibber that linked article is 404'd, did you write an Android app? Have any source code handy? – Lavamantis Dec 26 '21 at 15:44
  • 1
    I used Tasker, Wink and IFTTT (back when it was free). Don't have the scripts handy but they were fairly trivial. Today I'd probably use Tasker and something from this link: https://iot.stackexchange.com/questions/3437/are-there-any-smart-electrical-plugs-with-an-open-api – Kibber Dec 27 '21 at 20:25
10

Is there an Android API for stop charging even though physically the charging is on?

AFAIK no.

Justification:

android.intent.action.BATTERY_CHANGED is a protected intent that can only be sent by the system. Therefore you cannot duplicate or override the functionality.

citizen conn
  • 15,300
  • 3
  • 58
  • 80
8

You guys are all missing the point - the purpose of limiting charging is to increase battery lifespan by keeping it away from fully charged conditions (and near empty but that's a different issue). If you anticipate needing a full charge then tell it to charge to 100.

If you can't set a charge limit then the battery would rarely be idle and ideally charged when on the charger. It probably requires device level support though.

Brad
  • 81
  • 1
  • 1
  • 2
    The point of not charging to 100% is to avoid the faster aging when charging past 70% and heat combined. On the other side, draining to 0% has no adverse effect on battery aging and is already well protected as battery can go down to 2800mV without aging and most device limits it to 3200mV. Info taken from (hard-to-find) a battery manufacturer and a user testing drain manually. – 3c71 Oct 06 '13 at 05:32
  • 1
    @3c71, draining a lithium ion battery to 0% (or even to what the manufacturer tells you is "0%") most certainly is bad for the battery's longevity. – Nate May 23 '14 at 08:10
  • 1
    @Nate, not at all, I've done that on many devices and never lost any capacity, and the reason is very simple: battery deteriorate only when it's charge level goes below 2.8V which is way beyond the 3.2V / 0% set by manufacturer. Other electricians/engineers have also confirmed this with real tests and actual measures. – 3c71 May 24 '14 at 08:35
  • It's not just about managing charge, it's also about managing heat. For example, my device can auto-shutdown when it charges while the display is on while also recording video. Being able to "throttle" the charging down when heat levels rise would be quite helpful. – Darien May 05 '15 at 16:58
  • 1
    @3c71, I'm assuming you're the 3c71 of the BatteryMonitorWidget? Do you think BatteryMonitorWidget could support stopping of charging as described here: http://stackoverflow.com/a/36229927/4669417 ? – Kibber Mar 26 '16 at 00:02
  • @3c71 even going down to 20% is worse for the battery than going down only to 40%, for example. It's a scale. 0% is not detrimental, but if you can stay above it it's beneficial. Same thing for high percentages. – Lubo Kanev Feb 16 '22 at 07:53
8

https://play.google.com/store/apps/details?id=es.guille.stopcharge uses echo "0" > /sys/class/power_supply/battery/device/charge. It works for me on a nexus 4 (rooted), as long as the device isn't fully charged (in a charging state).

Also relevant: https://android.stackexchange.com/questions/15001/how-can-i-avoid-the-battery-charging-when-connected-via-usb

Community
  • 1
  • 1
theicfire
  • 2,719
  • 2
  • 26
  • 29
4

Contrary to some answers indicating it's not possible, it is, indeed possible with ROOT. You can find some apps on the Play Store that will allow you to do this (with root permission, of course).

The best app that works on every phone I've tried it on is Battery Charge Limit. You can download it from the Play Store or the XDA discussion thread. The app is under active development so, if you find that your phone isn't supported, just submit an issue on its GitHub page.


NB: I am not the developer of this application.

Alex Essilfie
  • 12,339
  • 9
  • 70
  • 108
2

This is unfortunately not possible. Android only have read APIs for battery data.

Battery charging control is internal to the Android kernel and battery IC modules. Manufacturers do change it from time to time, like HTC is having small cycles from 95-100% (a bad idea IMO), Samsung does stop charges as soon as it reaches 100%, but I've never seen a device able to stop charging before 100% to reduce battery aging :(.

At best if we're lucky, a sysfs interface might help do that, but it requires root and will differ from device to device.

3c71
  • 4,313
  • 31
  • 43
1

Just to add to this. Samsung phones do not stop charging after 100%. As far as I'm aware they "trickle" charge past this point however they recommend you do not charge your phone past 100% for over 1 hour. Battery manufacturers like Anker also state the same so the idea of stopping the charge at 100% would be really useful. The risks of leaving the phone on charge are battery bloat and eventually cell rupture. I wasn't aware of this to start off with an killed my samsung battery within 3 months of owning the phone.

To expand on the original question. I've noticed some kernels allow fast charging. If they are able to alter the charge rate up could we alter the charge rate down (trickle) to meet a desired finish time (when your morning alarm goes off)??

0

I have installed a timer on the AC receptacle where I plug my Moto E's charger into. After guestimating how much time the battery needs to charge to about 85%, I set the timer. This is not my idea of a solution, but at least it keeps my phone from being charged to 100%, as I usually err on the short side when setting the timer.

-1

I dont think there would be such an api. If it does exist it needs to be supported by the device manufacture as its not a pure OS lever feature. The same reason would make it a bad idea to use it as not all devices will support it.

That being said it would be a bad idea to use/implement it , mobile devices are not built to directly run from the power supply and a user will not plug in the cable if he/she did not want to actually charge the device.

Ravi Vyas
  • 12,212
  • 6
  • 31
  • 47
  • The reason I want to do it is that i want to develop an app that will stop charging when the battery is full and start charging again when it say 95%. it would save a lot of electricity because instead of charging all night, the charger will work only the time it needs to work. think green... – daniel Jul 11 '11 at 19:28
  • @daniel I believe the phone does that already (possibly not 95% but some percentage < 100). Read this: http://www.androidcentral.com/bump-charging-what-it-and-how-do-it – Glendon Trullinger Jul 11 '11 at 19:35
  • @Glendon Trullinger you have a valid point , guess only developers face it :-) , on the side note keeping the screen off/locked when not needed does seem to help the temperature issue on my end – Ravi Vyas Jul 11 '11 at 19:36
  • @Ravi I deleted my comment because I realized I could remove the battery to try to attempt to combat that specific issue. I'll be trying that soon XD – Glendon Trullinger Jul 11 '11 at 19:38
  • Interesting.. just tried it on mine (Droid X) and got the same while plugged into USB. It does, however, run fine when plugged into the wall without a battery. I guess USB doesn't output enough power to keep the thing running. – Glendon Trullinger Jul 11 '11 at 20:42