adb shell“screencap -p /sdcard/screen.png”失败,并显示“设备上没有剩余空间”,但有足够的空间

问题描述 投票:0回答:1

有人遇到过并解决过这样的问题吗?

我们使用 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"
成功,但仅成功一次。 当我们尝试通过相机拍照来保存图片时 - 没有报告问题

什么可能导致“无空间”错误?

android adb screen-capture
1个回答
0
投票

您正在使用的位置很可能不存在。

您可以尝试一些列出的存储位置。

/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"
© www.soinside.com 2019 - 2024. All rights reserved.