Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Ider
Last active September 11, 2018 20:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ider/bbdc050cc4c510c6880551b957f108f2 to your computer and use it in GitHub Desktop.
Save Ider/bbdc050cc4c510c6880551b957f108f2 to your computer and use it in GitHub Desktop.
Capture or record android screen, pull file to Mac when it's completed
# Demo: https://www.youtube.com/watch?v=4GsUf5OQAlI
# capture screen of android device
andrdroidScreenCapture() {
curTime=`date +%Y-%m-%d-%H-%M-%S`
tmpeName="$curTime.png"
[[ -n $1 ]] && fileName=$1 || fileName=$tmpeName
devicePath="/sdcard/$tmpeName"
adb shell screencap -p $devicePath
adb pull $devicePath $fileName
adb shell rm $devicePath
}
export ADB_SHELL_SCREENRECORD_ARGS='--verbose --bit-rate 2000000'
# record screen of android device
androidScreenRecord() {
echo -e "\033[1m(press Ctrl-C to stop recording)\033[0m"
curTime=`date +%Y-%m-%d-%H-%M-%S`
tmpeName="$curTime.mp4"
[[ -n $1 ]] && fileName=$1 || fileName=$tmpeName
devicePath="/sdcard/$tmpeName"
adb shell screenrecord $ADB_SHELL_SCREENRECORD_ARGS $devicePath
sleep 1 # wait for video encoding finish
adb pull $devicePath $fileName
# Don't delete copy in device.
# adb shell rm $devicePath
open $fileName
}
function asc() {
if [[ -z $1 ]]; then
echo "Please provide a filename."
echo "Provideing .png extension for capturing the device screen, and providing .mp4 for recording the device screen."
return
fi
if [[ $1 == *.png ]]; then
andrdroidScreenCapture $1
elif [[ $1 == *.mp4 ]]; then
androidScreenRecord $1
else
echo "Filename with unknow extension, only .png and .mp4 are supported"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment