0

I am working on a battery monitoring app in which I have to show battery usage for all apps. After a lot of googling I found there a only way to do so is using command line

$ adb shell dumpsys batterystats --charged --checkin

The above command will provide all battery stats but I don't know how can I get this data in my code?

Please help!

2 Answers2

0

Following code to show Summary of all apps battery usage, So you can try this.

Intent sample = new Intent("android.intent.action.POWER_USAGE_SUMMARY"); startActivity(sample);

Manukumar
  • 381
  • 1
  • 4
  • 11
0

You can grab dumpsys information on the device, but it does require permissions which are not granted to regular applications.

The shell-user has permission to run the command however - if you're running an on-device test using Instrumentation you can use Instrumentation.getUiAutomation().executeShellCommand(...) to execute the command as the shell user.

Colt McAnlis
  • 3,846
  • 3
  • 18
  • 19