使用adb获取手机截屏

为了方便获取手机的截屏,把这个过程写成bat脚本,先上代码:

@echo off
set tsp="%time:~0,1%"
if %tsp%==" " (set date_time=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%) else (
set date_time=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
)
set filename=%date_time%.png
echo %filename%
adb wait-for-device
::截屏,并将文件放置在/sdcard/这个目录下面
adb shell screencap /sdcard/%filename%
::导出截屏到脚本所在的文件夹
adb pull /sdcard/%filename%
::判断是否成功获取到了截屏文件
if %errorlevel% equ 0 (
	echo "get %filename% success!!!"
) else (
	echo "get %filename% fail!!!"
)
pause

截屏的命令

adb shell screencap [filename]

filename为截屏在手机中的全路径名

下面这段脚本是获取当前时间,用来设置截屏文件的名称,具体解释见这篇文章windows脚本语法

set tsp="%time:~0,1%"
if %tsp%==" " (set date_time=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%) else (
set date_time=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
)

你可能感兴趣的:(adb)