android - adb shell "screencap -p /sdcard/screen.png" 失败并显示“设备上没有剩余空间”,但有足够的空间
问题描述
有人遇到并解决了这样的问题吗?
我们使用 adb shell screencap 命令在 Android 设备上截屏:
//catch and download screenshot
adb shell "screencap -p /sdcard/screen.png"
adb pull "/sdcard/screen.png" "tempPictPathName"
//clean
adb shell "rm /sdcard/screen.png"
它工作了很长时间。由于某种原因(在我们的代码中没有改变,在被测设备上也没有改变),当从 cmd 和代码运行相同的命令时,我们开始收到“设备上没有剩余空间”错误:
>adb shell "screencap -p /sdcard/screen.png"
Error opening file: /sdcard/screen.png (No space left on device)
我们检查了,设备上有足够的空间:
$ ls -l /storage/
lrwxrwxrwx root root 2018-12-16 10:35 sdcard -> /storage/emulated/legacy
$su -c df
Filesystem Size Used Free Blksize
/storage/emulated 930.4M 0.0K 930.4M 4.0K
/storage/emulated/0 8.9G 6.1G 2.9G 4.0K
/storage/emulated/0/Android/obb 8.9G 6.1G 2.9G 4.0K
/storage/emulated/legacy 8.9G 6.1G 2.9G 4.0K
/storage/emulated/legacy/Android/obb 8.9G 6.1G 2.9G 4.0K
我们尝试更改 .png 文件的位置但没有成功:
>adb shell "screencap -p /sdcard/Download/screen.png"
Error opening file: /sdcard/Download/screen.png (No space left on device)
>adb shell "screencap -p /storage/sdcard/Download/screen.png"
Error opening file: /storage/sdcard/Download/screen.png (No space left on device)
设备重新启动后,命令adb shell "screencap -p /sdcard/screen.png"
成功但只有一次。当我们尝试通过相机拍照来保存照片时 - 没有报告问题
什么会导致“无空间”错误?
解决方案
很可能您正在使用的位置不存在。
您可以尝试一些列出的存储位置,即。
/storage/emulated
/storage/emulated/0
所以你的代码应该是:
//catch and download screenshot
adb shell "screencap -p /storage/emulated/0/screen.png"
adb pull "/storage/emulated/0/screen.png" "tempPictPathName"
//clean
adb shell "rm /storage/emulated/0/screen.png"
如果这不可能,您可以使用以下命令:
# open the device shell
adb shell
# find your path in the device
pwd
# list all directories of this location
ls -la
# move into a directory with name dir_name
cd dir_name
# repeat "ls" and "pwd" commands as many times you need for the navigation
# when you find the location you want to put the recoding use again pwd to get the full path
pwd
其他替代方法可以是使用变量$EXTERNAL_STORAGE
adb shell "screencap -p $EXTERNAL_STORAGE/screen.png"