Skip to content

Instantly share code, notes, and snippets.

@FollowMeDown
Forked from sharana04/capture_image.py
Created June 5, 2018 12:57
Show Gist options
  • Save FollowMeDown/1b265ee45168902ca2c3f1dde882d6f7 to your computer and use it in GitHub Desktop.
Save FollowMeDown/1b265ee45168902ca2c3f1dde882d6f7 to your computer and use it in GitHub Desktop.
python script to automatically capture images from front and back camera.
import uiautomator,os,sys,datetime,time
from uiautomator import Device
print 'Getting Device Info'
os.system('adb devices > deviceinfo')
devinf = open('deviceinfo','rb')
devlines = devinf.readlines()
devinf.close()
for i in range(len(devlines)):
if 'device' not in devlines[i]:continue
dev = devlines[i].split('\t')[0]
print dev
device = Device(dev)
print "taking picture from back camera"
os.system('adb shell am start -a android.media.action.IMAGE_CAPTURE --ei android.intent.extras.CAMERA_FACING 0')
time.sleep(4)
if device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/shutter_button_photo").exists :
device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/shutter_button_photo").click()
time.sleep(4)
if device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/btn_done").exists :
device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/btn_done").click()
time.sleep(10)
os.system('adb shell pm clear com.android.gallery3d')
print "capturing picture from front camera"
os.system('adb shell am start -a android.media.action.IMAGE_CAPTURE --ei android.intent.extras.CAMERA_FACING 1')
time.sleep(4)
if device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/shutter_button_photo").exists :
device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/shutter_button_photo").click()
time.sleep(4)
if device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/btn_done").exists :
device(className="android.widget.ImageView",resourceId="com.android.gallery3d:id/btn_done").click()
time.sleep(10)
os.system('adb shell pm clear com.android.gallery3d')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment