Android programmatically get battery usage per application
Asked Answered
L

1

8

android how to get battery usage per application. i have seen the applications that provides the battery used per application, but i do not find the api for this.reference link for the application application that perform the same

Lingonberry answered 26/4, 2014 at 12:43 Comment(5)
There is no documented and supported API for this. It is also blocked as of Android 4.4 -- only system apps can hack their way into the OS to try to glean this data. And the data is not especially good in the first place.Combustion
but many applications claim that they provide the information about battery usage per application.Lingonberry
All are written by developers who hacking into the OS to try to get this data. None will work on Android 4.4+, except by users of rooted devices who can install those apps on the system partition. And none of the data is especially accurate, as only specially instrumented devices (e.g., Qualcomm MDP series) have the capability of providing actual power usage at a fine-grained level. Instead, the OS guesses, based upon some rough heuristics, and uses that data for the Battery screen in Settings.Combustion
Hi,can we you please provide the info how they do this.Lingonberry
Maybe the comments are old, but they aren't correct at least currently because apps like GSam Battery Monitor can access battery stats per app and no root access is required eitherBackstage
C
-4

In the system level its showing some required information to get per application power consumption(Power Profiling) when we run the command "adb shell dumpsys batterystats"

And the output is given below which was redirected to a output file.We can parse it and use the below part from one Java application which can be run in outside of Android.

Device battery use since last full charge Amount discharged (lower bound): 63 Amount discharged (upper bound): 69 Amount discharged while screen on: 38 Amount discharged while screen off: 31

Estimated power use (mAh): Capacity: 2300, Computed drain: 1007, actual drain: 1449-1587 Unaccounted: 442 Screen: 398 Phone calls: 108 Uid 1000: 97.0 Wifi: 75.4 Idle: 61.6 Uid 0: 57.6 Uid u0a157: 32.1 Cell standby: 29.7 Uid u0a163: 21.8 Uid u0a8: 20.1 Uid 1013: 14.7 Uid u0a10: 13.2 Uid u0a22: 12.6 Uid u0a70: 11.5 Uid u0a99: 10.1 Uid u0a4: 9.40 Uid u0a20: 7.92 Uid u0a93: 5.49 Uid 1001: 5.47 Uid u0a92: 5.35 Uid u0a94: 2.27 Uid u0a16: 2.22 Uid u0a56: 0.713 Uid u0a67: 0.675 Uid u0a165: 0.670 Uid u0a34: 0.589

Yes, here the question remain unanswered how can we do it from one android application.

Battery Stats Output Logs

Cedar answered 11/5, 2015 at 10:10 Comment(1)
link provided is invalidMesenchyme

© 2022 - 2024 — McMap. All rights reserved.