本人在学习uiautomator的时候,碰到有时候无法通过程序验证或者需要截图时,需要在截图的名字里保留时间信息,所以写了一个截图并且以当前时间命名图片的方法
public void screenshot() {
Date a = new Date();
SimpleDateFormat b = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String c = b.format(a);
System.out.println(c);
File files = new File("/mnt/sdcard/aaa/"+c+".png");
getUiDevice().takeScreenshot(files);
}