如何通过 wifi 自动 adb 连接到设备

rus*_*ush 6 android adb genymotion

我有一个通过 wifi 通过 adb 连接的 android 设备。现在,由于某种原因,使用命令“adb kill-server”杀死了 adb 服务器。

一旦我重新启动服务器或发出命令“adb devices”,我希望通过 wifi 连接的设备出现在设备列表中,就像通过 USB 连接的设备出现在列表中一样。

如何做到这一点?我可以将设备的 ipaddresses 放在某个文件中,并且当 adb 服务器重新启动时它们会自动连接吗?

Kib*_*ard 11

我已经制作了批处理脚本,用于自动设置 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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

这两个脚本都要求 adb 位于您的路径中或与脚本位于同一文件夹中。


小智 0

如果未使用 USB 数据线连接设备,您将无法通过 WiFi 自动连接设备。我开发了一个开源 IntelliJ 插件,可以尽快完成此任务。这里有代码https://github.com/pedrovgs/AndroidWiFiADB,这里有插件https://plugins.jetbrains.com/plugin/7983