I am trying to automate 'taking a screenshot' on Galaxy S4 and Kindle HDX 8.9 and I am using the following code.
if(!(getUiDevice().takeScreenshot(new File("ANYPATH"))))
System.out.println("False: Screenshot not taken!!");
else
System.out.println("Gangnam Style...");
ANYPATH values I tried:
Irrespective of the path I try, the condition always returns false and the screenshot is not taken on any of the devices (actual devices and not an emulator). I am not sure what am I missing here?
I am just following the syntax from http://developer.android.com/tools/help/uiautomator/UiDevice.html#takeScreenshot(java.io.File)
Regards, Rumit
The takeScreenshot() method is applicable from 4.2 and above android version devices.
If the device version is appropriate then use the following piece of code.
File path = new File("/sdcard/filename.png");
int SDK_VERSION = android.os.Build.VERSION.SDK_INT;
if (SDK_VERSION >= 17) {
mUiAutomatorTestCase.getUiDevice().takeScreenshot(PATH);
}
We can view the file by following command.
$ adb shell ls -l /sdcard/name-of-file