ADB 代表Android Debug Bridge,它是一个实用程序,您可以安装在您的计算机上以在您的Android 设备(Android device)上执行操作。如果您曾经为您的Android 设备(Android device)搜索过任何自定义选项,那么您可能听说过此实用程序,因为它也用于自定义Android 设备(Android device)。
在大多数情况下,ADB用于通过 USB 连接从您的计算机向您的Android 设备(Android device)发送和执行命令。但是,它也可以通过无线连接工作。真正奇怪的是,没有多少人谈论该实用程序的这个有用功能。
通过在您的Android 设备(Android device)上无线使用ADB,您不需要任何乱七八糟的电缆,您可以直接从您的计算机无线执行各种操作,包括截屏、安装应用程序、删除应用程序等。
将 ADB 无线用于无根 Android 设备(Use ADB Wirelessly For Non-rooted Android Devices)
如果您还没有植根您的 Android 设备或者您不知道它是什么,那么在您能够无线使用ADB之前,您需要执行一个额外的步骤。
您需要先使用USB 电缆(USB cable)将设备连接到计算机,然后启动ADB 服务器(ADB server)。这是因为无线ADB 模式(ADB mode)通常不会启动将计算机连接到设备所需的服务器。
通过 USB 连接启动 ADB 设置(Initiating The ADB Setup Over a USB Connection)
- 前往ADB 网站并(website and download)在您的计算机上下载并解压缩该软件包。
- 在您的Android 设备(Android device)上启动设置(Settings)应用程序,点击开发人员选项(Developer options),然后启用显示USB 调试(USB debugging)的选项。这是让您通过ADB将计算机连接到(ADB)Android的选项。
- (Plug-in)使用USB 电缆(USB cable)将您的Android 设备(Android device)插入计算机。
- 在您刚刚从包中提取的ADB 文件夹(ADB folder)中启动命令提示符窗口(Command Prompt window)( Windows ) 或终端窗口(Terminal window)( Mac ) 。在窗口中输入以下命令,然后按 Enter(Enter)。adb 设备(adb devices)(Windows) ./adb devices(Mac)
- 询问您是否要允许USB调试的提示将出现在您设备的屏幕上。选中(Checkmark)始终允许从此计算机(Always allow from this computer)框并点击OK。
- 您会在命令行窗口中看到您的(command line window)Android 设备(Android device)。输入以下命令并按(command and hit)Enter。此命令不会有输出。adb tcpip 5555 (Windows) ./adb tcpip 5555 (Mac)
您已成功在端口号 5555(port number 5555)上设置ADB 服务(ADB service)。
找出Android设备的IP地址(Finding Out The IP Address Of The Android Device)
现在ADB 服务器(ADB server)已启动并运行,您已准备好从计算机连接到您的设备。但是,要做到这一点,您需要先找出设备的IP 地址(IP address)。
此外,请确保您的设备连接到与计算机相同的无线网络(wireless network)。
- 在您的Android 设备(Android device and tap)上启动设置(Settings)应用程序,然后点击底部的关于手机。(About phone)
- 在以下屏幕上,点击显示状态(Status)的选项,该选项可让您查看网络详细信息。
- (Scroll)在以下屏幕上向下滚动,您会发现一个条目说IP地址(IP address)。这是您将使用的地址,因此请记下某处。
您现在知道您的设备在网络上的位置,是时候在您的两台机器之间建立连接了。
使用 ADB 无线连接到 Android 设备(Connect Wirelessly To An Android Device Using ADB)
您现在将从您的计算机向您的设备发送一个请求,要求建立连接。由于您的计算机已经是USB 调试(USB debugging)的授权机器之一,因此您不会收到提示或(prompt or anything)类似的请求您的许可。
- 返回命令行窗口(command line window),输入以下命令,然后按 Enter 键(Enter)。请务必将IP替换为您的Android 设备(Android device)的实际IP 地址(IP address)。adb 连接 IP(adb connect IP)
- 如果一切顺利,命令行将(command line)输出一条消息,说明您现在已连接到指定的IP 地址(IP address)。
现在您已使用ADB连接到您的(ADB)Android 设备(Android device),您可以发出任何您知道的ADB命令,这些命令将在您的Android 手机(Android phone)上执行。
将 ADB 无线用于 Root 的 Android 设备(Use ADB Wirelessly For Rooted Android Devices)
如果您在您的设备上获得了 root 访问权限,那么从您的计算机连接到您的设备将不需要服务器初始化过程(initialization process)。这意味着您无需先使用USB 电缆(USB cable)连接设备。
不过,您需要设备的IP 地址(IP address)。
- 前往Google Play 商店并在您的设备上下载(Google Play Store and download)并安装终端模拟器(Terminal Emulator)应用程序。
- 运行以下命令并在您的设备上为应用程序提供 SU 权限。
苏(su)
- 一一键入以下命令(command one),这些命令将初始化ADB 连接(ADB connection)所需的一切。
setprop service.adb.tcp.port 5555
停止 adbd
启动 adbd(setprop service.adb.tcp.port 5555stop adbdstart adbd)
- 在计算机的命令行窗口(command line window)中运行以下命令,将IP替换为设备的IP 地址(IP address)。它将使用ADB连接到您的设备。adb 连接 IP(adb connect IP)
您现在可以在设备上运行您想要的任何命令。此外,由于您的设备已植根,您甚至可以运行需要超级用户权限的命令。
首先要尝试什么亚行命令(What ADB Commands To Try Out First)
如果您以前从未在ADB中运行过任何命令,那么您可以首次运行一些有用的命令并在您的设备上完成任务。
- 重启设备 – adb reboot
- 发送文件到设备 - adb push source target
- 从设备获取文件 – adb pull source target
- 安装应用程序 - adb install app-name.apk
- 卸载应用程序 – adb uninstall package-name
- 截图 – adb shell screencap -p /sdcard/capture.png然后使用adb pull /sdcard/capture.png将截图拉到你的电脑上
完成后,运行adb disconnect命令断开与Android 设备(Android device)的连接。
How To Use ADB Wirelessly On Your Android
ADB stands for Android Debug Bridge and it’s a utility you can install on your computer to perform actions on your Android device. If you’ve ever searched for any customization options for your Android device, you’ve likely heard of this utility as it’s used to customize Android devices as well.
In most cases, ADB is used over a USB connection to send and execute commands from your computer to your Android device. However, it works over a wireless connection as well. It’s really strange that not a lot of people talk about this useful feature of the utility.
By using ADB wirelessly with your Android device, you don’t need any mess of cables and you can perform various actions including taking screenshots, installing apps, removing apps, and so on, right from your computer wirelessly.
Use ADB Wirelessly For Non-rooted Android Devices
If you haven’t rooted your Android device or you don’t know what it is, then there’s an extra step you need to follow before you’re able to use ADB wirelessly.
You’ll need to first connect your device to your computer using a USB cable and then start the ADB server. It’s because the wireless ADB mode often doesn’t start the server required to connect your computer to your device.
Initiating The ADB Setup Over a USB Connection
- Head over to the ADB website and download and extract the package on your computer.
- Launch the Settings app on your Android device, tap on Developer options, and enable the option that says USB debugging. This is the option that lets you connect your computer to your Android over ADB.
- Plug-in your Android device to your computer using a USB cable.
- Launch a Command Prompt window (Windows) or Terminal window (Mac) in the ADB folder that you just extracted from the package. Type in the following command into the window and hit Enter.
adb devices (Windows)
./adb devices (Mac)
- A prompt asking if you’d like to allow USB debugging will appear on your device’s screen. Checkmark the Always allow from this computer box and tap on OK.
- You’ll see your Android device listed in your command line window. Type in the following command and hit Enter. There won’t be an output for this command.
adb tcpip 5555 (Windows)
./adb tcpip 5555 (Mac)
You’ve successfully set up the ADB service on port number 5555.
Finding Out The IP Address Of The Android Device
Now that the ADB server is up and running, you’re ready to connect to your device from your computer. To be able to do it, though, you’re going to need to first find out the IP address of your device.
Also, make sure your device is connected to the same wireless network as your computer.
- Launch the Settings app on your Android device and tap on About phone at the bottom.
- On the following screen, tap on the option that says Status which will let you see your network details.
- Scroll down on the following screen and you’ll find an entry saying IP address. This is the address you’ll be using so note it down somewhere.
You now know the location of your device on your network and it’s time to establish a connection between two of your machines.
Connect Wirelessly To An Android Device Using ADB
You’ll now send a request from your computer to your device asking to make a connection. Since your computer is already one of the authorized machines for USB debugging, you won’t get a prompt or anything like that asking for your permission.
- Get back to your command line window, type in the following command, and hit Enter. Be sure to replace IP with the actual IP address of your Android device.
adb connect IP
- If all goes well, the command line will output a message saying you’re now connected to the specified IP address.
Now that you’re connected to your Android device using ADB, you can issue any of the ADB commands you know and those will be executed on your Android phone.
Use ADB Wirelessly For Rooted Android Devices
If you’ve gained root-access on your device, then connecting to your device from your computer won’t require server initialization process. This means you won’t need to first connect the device using a USB cable.
You’ll need the IP address of your device, though.
- Head over to the Google Play Store and download and install the Terminal Emulator app on your device.
- Run the following command and provide the app with SU permissions on your device.
su
- Type in the following command one by one and these will initialize everything required for an ADB connection.
setprop service.adb.tcp.port 5555
stop adbd
start adbd
- Run the following command replacing IP with the IP address of your device on your computer’s command line window. It’ll connect to your device using ADB.
adb connect IP
You can now run any of the commands you want on your device. Also, since your device is rooted, you can even run commands that require superuser permissions.
What ADB Commands To Try Out First
If you’ve never run any commands in ADB before, there are a few useful commands that you can run for the first time and get things done on your device.
- Reboot device – adb reboot
- Send file to the device – adb push source target
- Get file from the device – adb pull source target
- Install an app – adb install app-name.apk
- Uninstall an app – adb uninstall package-name
- Take a screenshot – adb shell screencap -p /sdcard/capture.png and then use adb pull /sdcard/capture.png to pull the screenshot to your computer
When you’ve finished, run the adb disconnect command to disconnect from your Android device.