I want to know how much my application using battery of user's mobile programmatically. I search for it but not able to find any specific solution for it.
Asked
Active
Viewed 1,233 times
1
-
Does this answer your question? [Get battery level and state in Android](https://stackoverflow.com/questions/3291655/get-battery-level-and-state-in-android) – Andreas is moving to Codidact Jul 24 '20 at 17:43
-
Take a look at https://github.com/facebookincubator/Battery-Metrics – Ryan M Jul 25 '20 at 02:31
1 Answers
1
If you are trying to configure usage for your battery from your app, you cannot. If you are trying to know how much battery is left in your device you can.
Suggestion: One thing you can do is start a session once your app opens and end it when you close. That way you can know how much battery was used. Again, other factors like background apps and multitasking comes into play hence you cannot identify it. Maybe these links can help you.
https://developer.android.com/topic/performance/power/battery-historian
https://developer.android.com/training/monitoring-device-state/battery-monitoring#java
Again I might be wrong here. Comments and edits are welcome.

sanjeev
- 1,664
- 19
- 35
-
i have refer this links but this gives just battery charging state information not give the information about battery usage by application – p.k. Aug 13 '19 at 07:39
-
Well you still haven't told what are you planning to do with getting the info's. – sanjeev Aug 13 '19 at 08:35
-
I have make an application and i want to know how much battery it will uses on user's mobile – p.k. Aug 13 '19 at 09:35
-
This would be a valid answer if it wasn't for split screen, preserving state while the app is in the background, and Oreo's new picture in picture mode. There's a lot that can drain the battery that *isn't* the app now. – Zoe Aug 13 '19 at 15:10
-
@Zoe yeah now it makes it even harder to determine.. Then I think the only way to determine app's battery usage is through battery statistics from settings? – sanjeev Aug 14 '19 at 03:58
-
Yeah, that or through the API, but I'm not sure if the latter is supported – Zoe Aug 14 '19 at 07:33