亚行外壳程序“ screencap -p /sdcard/screen.png”失败,显示“设备上没有剩余空间”,但是有足够的空间

时间:2018-12-16 13:03:53

标签: android adb screen-capture

有人经历并解决了这个问题吗?

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

什么会导致“无空格”错误?

1 个答案:

答案 0 :(得分: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"