How to Keep ADB Connected Over Your Phone Hotspot
This is a simple, step-by-step guide to keep your ADB connection over a phone hotspot using Windows. No CSS or JavaScript is used.
Step 1: Prerequisites
- Windows PC with ADB installed (part of Android Platform Tools).
- Phone with USB debugging enabled in Developer Options.
- Phone and PC connected to the same hotspot network.
Step 2: Enable ADB over Wi-Fi (Temporary)
Connect your phone to PC via USB and open Command Prompt or PowerShell, then run:
adb devices adb tcpip 5555 adb shell ip route # optional, shows phone IP
After this, you can unplug the USB cable.
Step 3: Connect over Wi-Fi
Run the following command with your phone's IP:
adb connect <phone-ip>:5555 adb devices # to check connection
You should see your device listed as connected over Wi-Fi.
Step 4: Automatic Reconnect Script
To auto-reconnect whenever your hotspot is active, save the following as adb-autoconnect.ps1:
$port = 5555
$subnet = "192.168.43" # change if your hotspot uses a different subnet
function Try-Connect([string]$ip) {
$addr = "$ip`:$port"
$devices = & adb devices 2>&1
if ($devices -match [regex]::Escape($addr) + "\s+device") { return $true }
if (Test-Connection -ComputerName $ip -Count 1 -Quiet -ErrorAction SilentlyContinue) {
Write-Host "Trying adb connect $addr"
& adb connect $addr | ForEach-Object { Write-Host $_ }
Start-Sleep -Seconds 2
$devices = & adb devices 2>&1
if ($devices -match [regex]::Escape($addr) + "\s+device") { return $true }
}
return $false
}
Write-Host "Starting ADB auto-connect"
while ($true) {
for ($i=1; $i -le 254; $i++) {
$ip = "$subnet.$i"
if (Try-Connect $ip) { Write-Host "Connected to $ip:$port"; break 2 }
}
Write-Host "No device found. Retrying in 8 seconds..."
Start-Sleep -Seconds 8
}
Step 5: Run the Script
- Open PowerShell as your user.
- Enable local scripts:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force - Run the script:
.\adb-autoconnect.ps1
Step 6: Optional — Run at Windows Login
Create a shortcut to PowerShell with this target:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "C:\path\to\adb-autoconnect.ps1"
Place it in the Startup folder or use Task Scheduler to run automatically at login.
Security Tips
- Keep your hotspot password-protected.
- Use
adb disconnect <ip>:5555when done or reboot phone to close TCP listener. - If your phone supports Wireless Debugging (Android 11+/MIUI 12+), consider pairing method for secure connection.
Troubleshooting
- If
adb connectfails, ensure both devices are on the same subnet and TCP/IP ADB was enabled at least once via USB. - Use
adb kill-serverandadb start-serverif connection issues persist.
Comments
Post a Comment