dumpsys window | grep "mCurrentFocus" | tail -n 1 | awk '{print $NF}' | cut -d'}' -f1 com.rxgb.launcher/com.rxgb.launcher.activity.MainActivity
时间: 2024-03-01 14:56:10 浏览: 115
您的命令输出了当前活跃窗口的信息,因此 `get_display_id` 函数实现正确。您可以尝试在 `get_display_id` 函数中添加一些调试信息,例如在 `echo "$focus"` 和 `echo "$displays"` 后面再添加一行 `echo "focus=$focus displays=$displays"`,以便了解函数中每个变量的值。例如:
```
get_display_id() {
local focus=$(dumpsys window | grep "mCurrentFocus" | tail -n 1 | awk '{print $NF}' | cut -d'}' -f1)
local displays=$(dumpsys window | grep display | grep 'imeInputTarget')
echo "$focus"
echo "$displays"
echo "focus=$focus displays=$displays"
echo $displays | grep "$focus"
}
```
这样可以帮助您找出问题所在。另外,您也可以尝试在脚本中添加一些错误处理代码,例如在 `dumpsys window` 命令执行失败时输出错误信息。例如:
```
get_display_id() {
local focus=$(dumpsys window | grep "mCurrentFocus" | tail -n 1 | awk '{print $NF}' | cut -d'}' -f1)
if [ -z "$focus" ]; then
echo "Error: Failed to get current focus."
return 1
fi
local displays=$(dumpsys window | grep display | grep 'imeInputTarget')
if [ -z "$displays" ]; then
echo "Error: Failed to get displays information."
return 1
fi
echo "$focus"
echo "$displays"
echo "focus=$focus displays=$displays"
echo $displays | grep "$focus"
}
```
这样可以更加健壮地处理异常情况。
阅读全文