android adb shell“screencap -p/sdcard/screen.png”失败,显示“No space left on device”,但有足够的空间

k4ymrczo  于 2023-05-27  发布在  Android
关注(0)|答案(1)|浏览(206)

有没有人经历过并解决过这样的问题?
我们使用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和代码运行相同的命令时,我们开始收到“No space left on device”错误:

>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"命令成功,但仅成功一次。当我们尝试通过相机拍照来保存图片时-没有报告问题
什么原因会导致“无空间”错误?

yh2wf1be

yh2wf1be1#

您访问的页面不存在。
您可以尝试一些列出的存储位置,即.

/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"

相关问题