Gil's profile at Stack Overflow Coding challenges at Project Euler



ADB over wifi

The adb command is well known to Android developers, it provides utility commands such as shelling into a device, manipulating basic services like the activity manager, and pushing or pulling files from a device. What is not widely known is that you don't actually need an usb cable to talk to your device.

First, adb is made up of 3 components: adbd, a daemon running on the phone, adb server, a service running on your computer, and the adb command itself issued from your shell. When you type some adb command for the first time, the adb server is brought up on your computer and starts listening by default on port 5037. This is the port the adb command will talk to and receive data from. Another thing the adb server does is to monitor for connected devices, either from usb or from tcp (i.e. for their adbd daemons).

Now that we know the theory let's come down to business and connect our device through the wifi. For starters you need to connect your device through usb once. This is because by default adbd daemon will send data over usb and we need to change it to tcp. Once the device is connected, type in a shell:

adb tcpip 5678

where 5678 is a port of your choice. The adbd daemon is listening through tcp and you can unplug your device. The next step is to connect the adb server to the daemon on the device. In a shell type:

adb connect <device ip>:5678

where is the ip of your device. It can be found in Settings > About phone > Status > IP address. Now you are ready to go and do all your development over the air.

In case you want to disconnect your device you can issue:

adb disconnect <device ip>:5678

Also, to let adbd listen only over usb, while your device is still connected either thorough tcp or usb, you can execute:

adb usb

This post covers only one specific use case of adb. If you want to learn more about it, your first resource is here.