Search code examples
androidadbmonkeyrunner

Taking screenshots for battery analysis on android


I'm doing a battery analysis of my app, I'm left with these options only:

  1. Disable USB charging on the device, which I have not been able to do yet and take screenshot using monkeyrunner of Settings -> Battery screen
  2. Without the USB cable attached, I can use simulate the down volume key + power key hold event through a shell script running on my rooted phone to take the screenshot of the Settings -> Battery screen
  3. Get the dumpsys battery which shows all processes like its listed in Settings -> Battery again using a shell script running in adb shell on a rooted phone, but I do not know the command

Every method has its own limitations. Is there any way in which I can achieve my objective??


Solution

  • With the ICS and above, all phones are bundled in with a exe named screencap in /system/bin. Run the below command line to take a screenshot

    screencap -p /sdcard/screenshot.png
    

    This can also be done by grabbing shell using Java, so you can capture sceenshot as and when you will want to.