Skip to main content

How to Keep ADB Connected Over Phone Hotspot (Automatic Reconnect)

How to Keep ADB Connected Over Phone Hotspot (Automatic Reconnect)

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

  1. Open PowerShell as your user.
  2. Enable local scripts: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
  3. 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>:5555 when 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 connect fails, ensure both devices are on the same subnet and TCP/IP ADB was enabled at least once via USB.
  • Use adb kill-server and adb start-server if connection issues persist.

Comments

Popular posts from this blog

DevOps Best Practices

 # DevOps Best Practices: Your Ultimate Guide to Modern Software Development In today's fast-paced tech world, DevOps isn't just a buzzword – it's a game-changer. Let's dive into the essential practices that can transform your software development process. ![DevOps Lifecycle](https://blogger.googleusercontent.com/img/placeholder.png) ## 🔄 1. Continuous Integration (CI) - The Foundation Think of CI as your code's quality guardian. Every time developers push code, automated tests run to catch issues early. Here's what makes great CI: - Automated builds triggered with every commit - Comprehensive test suites running automatically - Code quality checks integrated into the pipeline - Quick feedback loops to developers **Pro Tip:** Start with simple automated tests and gradually build up your test suite. Remember, it's better to have a few reliable tests than many unreliable ones. ## 🚀 2. Continuous Delivery (CD) - From Code to Customer CD ensures your software ...

Introduction to Cloud Computing: Revolutionizing the Digital Landscape

In today's rapidly evolving digital world, cloud computing stands as a cornerstone of modern technology, transforming how businesses operate and individuals interact with data. Let's dive deep into this fascinating technology that powers our digital future. ## What is Cloud Computing? Imagine having a virtual supercomputer at your fingertips, accessible from anywhere in the world. That's the essence of cloud computing – a technology that delivers computing services such as storage, databases, software, and processing power over the internet, eliminating the need for physical hardware investments. ## The Three Pillars of Cloud Service Models ### Infrastructure as a Service (IaaS) Think of IaaS as renting the digital building blocks of computing. Companies like Amazon Web Services (AWS) and Microsoft Azure provide virtual machines, storage, and networking resources on-demand. This model offers unprecedented flexibility, allowing businesses to scale their infrastructure up or ...

How to Convert a Next.js Website into a PWA and TWA

🚀 Complete Guide: Converting Next.js to PWA & TWA Transform your Next.js website into a Progressive Web App and wrap it as an Android application using Trusted Web Activity. Every step explained in detail! 📋 Table of Contents What is a PWA? What is a TWA? Prerequisites & Setup Step 1: Convert Next.js to PWA Install Dependencies Configure next.config.js Create Web App Manifest Prepare App Icons Update Document Head Build and Test PWA Step 2: Wrap PWA as TWA Create Asset Links File Install Bubblewrap CLI ...