Ampere
Moderator: Martin
Re: Ampere
If you have root access, you could:
or
I suspect the unit is microamps.
Battery info in Android can be obtained from BatteryManager.
Code: Select all
cat /sys/class/power_supply/battery/current_avg
or
Code: Select all
cat /sys/class/power_supply/battery/current_now
Battery info in Android can be obtained from BatteryManager.
Last edited by heilong on 04 Nov 2016 11:50, edited 1 time in total.
Re: Ampere
Thanks heilong, unfortunately my device is not rooted, i will try to study "battery manager" to figure it out.
Re: Ampere
Most of the info, but not the charge currents, are easily obtained by creating a flow triggered by General Broadcast (android.intent.action.BATTERY_CHANGED), check "Receive initial sticky broadcast" - this allows you to run the flow manually any time and get the last broadcasted intent's value. You could either call this flow from another flow and get the results back, or you could set this flow up to store battery info properties in global variables. E.g. get intent extras - that works. But there's no extras for current.
Current info has been added to BatteryManager since API Level 21 (Android 5.0), to get them you need to get the BatteryManager system service. I've been able to get that info using Automagic's experimental functions for calling native Java code. An example flow is attached. If you're just using it for yourself, it should work as is. But ideally the script should first check if the API Level is >= 21.
Code: Select all
global_battery_level = getInt('level', -1);
Current info has been added to BatteryManager since API Level 21 (Android 5.0), to get them you need to get the BatteryManager system service. I've been able to get that info using Automagic's experimental functions for calling native Java code. An example flow is attached. If you're just using it for yourself, it should work as is. But ideally the script should first check if the API Level is >= 21.
- Attachments
-
- flow_BatteryGetCurrents_20161104_144849.xml
- (3.79 KiB) Downloaded 845 times
Re: Ampere
Rooted way is less reliable, too, because on different devices the /sys paths to the battery info are different.
On the other hand, Automagic's Java methods have a disclaimer that they are experimental and the API may change. I'm pretty sure if they're used in a wrong way, Automagic might crash.
On the other hand, Automagic's Java methods have a disclaimer that they are experimental and the API may change. I'm pretty sure if they're used in a wrong way, Automagic might crash.
Re: Ampere
Oh my god, it was so simple...there's already the variable in Automagic!
- Attachments
-
- Capture+_2016-11-04-15-03-44.png (198.33 KiB) Viewed 20303 times
Re: Ampere
That variable isn't available to me. Why is that happening?
Re: Ampere
Try this...ariloc wrote:That variable isn't available to me. Why is that happening?
- Attachments
-
- Capture+_2016-11-04-18-37-45.png (213.51 KiB) Viewed 20296 times
Re: Ampere
Oh yeah... Looks like the battery level condition provides all possible battery info.
So all my digging with callJavaMethod stuff was useless
Slight correction to your flow - your condition won't work if the battery level is exactly 100% (just unplugged). You should add the "false" branch (going same way as your "true" branch). You can also use {battery_current_now/1000} directly, no need for a script.
So all my digging with callJavaMethod stuff was useless

Slight correction to your flow - your condition won't work if the battery level is exactly 100% (just unplugged). You should add the "false" branch (going same way as your "true" branch). You can also use {battery_current_now/1000} directly, no need for a script.
Re: Ampere
Even better would be to config it to higher than 0%.heilong wrote:You should add the "false" branch (going same way as your "true" branch).
This same procedure is highly usable in many different cases with different conditions.