How to stop an android device from being charged programmatically?
Asked Answered
B

9

65

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

Bronco answered 11/7, 2011 at 17:46 Comment(2)
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 :(Chianti
#15994135 suggests it is possible on rooted devices?Breaux
I
14

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.

Ireneirenic answered 25/3, 2016 at 23:52 Comment(5)
Perfectly good solution. No idea why someone downvoted you. See How to automatically stop charging your phone.Semivowel
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).Ireneirenic
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 systemsCognomen
@kibber that linked article is 404'd, did you write an Android app? Have any source code handy?Strangulation
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: iot.stackexchange.com/questions/3437/…Ireneirenic
F
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.

Floriated answered 11/7, 2011 at 17:50 Comment(3)
What about this app ? play.google.com/store/apps/details?id=es.guille.stopchargeInkblot
^ requires ROOTCopybook
Would using that intent stop the phone from charging? If I send a battery at 100% intent as system, it will do it? (having the app as system app)Peculium
J
10

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

Juncture answered 7/1, 2016 at 0:32 Comment(0)
R
7

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.

Repeater answered 30/7, 2013 at 9:27 Comment(6)
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.Chianti
@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.Dumpcart
@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.Chianti
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.Directoire
@3c71, I'm assuming you're the 3c71 of the BatteryMonitorWidget? Do you think BatteryMonitorWidget could support stopping of charging as described here: https://mcmap.net/q/299652/-how-to-stop-an-android-device-from-being-charged-programmatically ?Ireneirenic
@Chianti 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.Markmarkdown
S
6

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.

Sieracki answered 20/8, 2018 at 8:46 Comment(1)
Thanks for sharing. It is great app. I have been looking for it for a long time.Kit
C
1

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.

Chianti answered 6/10, 2013 at 5:48 Comment(0)
H
0

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)??

Hypsography answered 4/4, 2014 at 12:44 Comment(0)
F
-1

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.

Forborne answered 4/2, 2016 at 3:16 Comment(0)
I
-2

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.

Isaacson answered 11/7, 2011 at 19:16 Comment(5)
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...Bronco
@Bronco I believe the phone does that already (possibly not 95% but some percentage < 100). Read this: androidcentral.com/bump-charging-what-it-and-how-do-itTelethon
@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 endIsaacson
@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 XDTelethon
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.Telethon

© 2022 - 2024 — McMap. All rights reserved.