相关文章推荐
跑龙套的毛豆  ·  WPF ...·  1 年前    · 
安静的油条  ·  sqlserver ...·  1 年前    · 
大方的红豆  ·  Jupyter lab 中 使用 ...·  1 年前    · 

android开发中经常使用到截屏、录屏等操作,当然使用系统自带的工具是没有问题的,但是在开发中,可能经常遇到手机截屏不方便操作、截屏可能不及时等问题,对于开发者不是很友好。此时可以考虑使用adb命令来截屏、录屏。

adb shell screencap -p /sdcard/123.png

由于screencap是手机命令,因此要先进入 adb shell .

usage: screencap [-hp] [-d display-id] [FILENAME]
   -h: this message
   -p: save the file as a png.
   -d: specify the physical display ID to capture (default: 19260720540627841)
       see "dumpsys SurfaceFlinger --display-id" for valid display IDs.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
yake@yakedeMacBook-Pro lottie-android % adb shell screencap

也可分步骤进行:

第一步:adb shell

第二步:adb screencap -p /sdcard/123.png

截屏之后图片保存到目录 /sdcard/123.png,可以使用命令保存到PC,adb pull /sdcard/123.png ./ 把保存的图片导出到PC当前目录。

adb shell screenrecord /dacard/123.mp4

adb shell screenrecord --h查看帮助:

Usage: screenrecord [options] <filename>
Android screenrecord v1.2.  Records the device's display to a .mp4 file.
Options:
--size WIDTHxHEIGHT
    Set the video size, e.g. "1280x720".  Default is the device's main
    display resolution (if supported), 1280x720 if not.  For best results,
    use a size supported by the AVC encoder.
--bit-rate RATE
    Set the video bit rate, in bits per second.  Value may be specified as
    bits or megabits, e.g. '4000000' is equivalent to '4M'.  Default 20Mbps.
--bugreport
    Add additional information, such as a timestamp overlay, that is helpful
    in videos captured to illustrate bugs.
--time-limit TIME
    Set the maximum recording time, in seconds.  Default / maximum is 180.
--verbose
    Display interesting information on stdout.
--help
    Show this message.
Recording continues until Ctrl-C is hit or the time limit is reached.

可见,默认最大可保存180秒(3分钟)的录屏。

3.自动化脚本

3.1 自动截屏并保存到本地

adb shell screencap -p /sdcard/tmp/123.png
adb pull /sdcard/tmp/123.png ./

3.2 自动录屏并保存到本地

adb shell screenrecord -p /sdcard/tmp/123.mp4
adb pull /sdcard/tmp/123.mp4 ./
复制代码
  • 私信