下面使用脚本实现该业务流程:
shell脚本:
#!/bin/sh
for times in $(seq 1000)
do
#启动相机
`adb shell am start com.android.camera/.CameraLauncher`
#延时2s
sleep 2s
#点击拍照按钮
`adb shell input tap 550 1760`
sleep 5s
#点击Back键退出相机
`adb shell input keyevent KEYCODE_BACK` #或者使用4代替KEYCODE_BAC
sleep 1s
echo $times
done
python:
#!/usr/bin/python
#coding=utf-8
import os
from time import sleep
def photo():
#注释省略
os.system('adb shell am start com.android.camera/.CameraLauncher')
sleep(2)
os.system('adb shell input tap 550 1760')
sleep(5)
os.system('adb shell input keyevent 4')
sleep(2)
if __name__ == '__main__':
total_times = 1000
times = 1
while (times <= total_times):
photo()
print times
times += 1
java:
package demo;
import java.io.IOException;
public class Photo {
public static void main(String[] args) {
int totalTimes = 1000;
int times = 1;
while (times <= totalTimes) {
photograph();
System.out.println(times);
times++;
}
}
private static void photograph() {
shell("am start com.android.camera/.CameraLauncher");
sleep(2000);
shell("input tap 550 1760");
sleep(5000);
shell("input keyevent 4");
sleep(2000);
}
private static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static void shell(String command) {
try {
Runtime.getRuntime().exec("adb shell " + command);
} catch (IOException e) {
e.printStackTrace();
}
}
}
#!/usr/bin/python
#coding=utf-8
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner import MonkeyDevice as md
device=mr.waitForConnection()
def photo():
#注释省略
device.startActivity(component='com.android.camera/.CameraLauncher')
mr.sleep(2)
device.touch(550, 1760, md.DOWN_AND_UP)
mr.sleep(5)
device.press('KEYCODE_BACK',md.DOWN_AND_UP)
mr.sleep(2)
if __name__ == '__main__':
total_times = 1000
times = 1
while (times <= total_times):
photo()
print times
times += 1