How to get information about android battery usage by application

点点圈 提交于 2019-11-26 12:43:57

问题


How can I get battery usage per application in Android.

I need to know % of battery spent by application.

Is it possible using SDK?

What I need is the information that\'s available on an Android device under \"Settings>About phone>Battery use\", but for specific applications

Thanks


回答1:


The project isn't complete by any stretch of the imagination, but I created an application framework (kinda...that was the goal, it's not there yet) to do just this. Check out http://syspower.googlecode.com. You won't be able to get the percentage by application unless you calculate the usage for all applications but you can get quantitative values for power consumption. You can obviously then use those numbers to calculate a percentage. Also, you should note that the power consumption API is private and in order to access it, I had to use a number of reflective calls to access private and hidden data members. Given that, it may or may not work with all Android versions (I've tested it with 1.6-2.1). I basically had to reverse engineer the FuelGuage app from the open source repository.




回答2:


I've viewed a lot and found that many APIs used in battery usage stats are from package "com.android.os.internal" which is not open to us.

I don't know if it's possible to implement this package by copy the code into our own project and import it. Just a thought. I think Chris's method maybe available.




回答3:


You can try out this command, though I'm not sure how to read its output:

adb shell dumpsys batterystats


来源:https://stackoverflow.com/questions/3770021/how-to-get-information-about-android-battery-usage-by-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!