我有一个 android 设备通过 adb 通过 wifi 连接。现在,由于某种原因,adb 服务器被使用命令杀死 'adb kill-server'。
一旦我重新启动服务器或发出命令 'adb devices',我希望通过wifi连接的设备出现在设备列表中,就像通过usb连接的设备出现在列表中一样。
如何实现?我可以将设备的 IP 地址放在某个文件中,并且当 adb 服务器重新启动时它们会自动连接吗?
最佳答案
我已经制作了批处理脚本,用于自动为 Wifi adb 网桥设置设备,获取 IP 并连接到它。您只需插入设备,运行脚本,然后再次拔下设备。
Windows 批处理(wifi-connect.bat):
@echo off
echo Disconnecting old connections...
adb disconnect
echo Setting up connected device
adb tcpip 5555
echo Waiting for device to initialize
timeout 3
FOR /F "tokens=2" %%G IN ('adb shell ip addr show wlan0 ^|find "inet "') DO set ipfull=%%G
FOR /F "tokens=1 delims=/" %%G in ("%ipfull%") DO set ip=%%G
echo Connecting to device with IP %ip%...
adb connect %ip%
pause
Unix/Mac (wifi-connect.sh)
#!/bin/sh
adb disconnect
adb tcpip 5555
sleep 3
IP=$(adb shell ip addr show wlan0 | grep 'inet ' | cut -d' ' -f6| cut -d/ -f1)
echo "${IP}"
adb connect $IP
这两个脚本都需要 adb 在您的 path 中或者在与脚本相同的文件夹中。
关于android - 如何通过wifi自动adb连接到设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29514151/