Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

ADB Common Commands (Android Debug Bridge)

2.40/5 (3 votes)
22 Feb 2016CPOL3 min read 22K  
A reference guide to using ADB to control an Android device from Windows
In this post, you will find some common commands I use to manipulate Android devices from the windows command line using ADB.

Introduction

Here are some common commands I use to manipulate Android devices from the windows command line using ADB (Android Device Bridge). The reason this page exists is because I generally forget them about 5 minutes later. I hope they are helpful.

Download the ADB tools from the Android developers web site, either with Android studio or on their own.

To use ADB, you do not have to root the device. But the phone does need to be in Android Developer mode. Setting the device to developer mode varies for different Android versions, but is normally done via the setting  screen on the device. Simply find the Android build number and press it 7 times, it will tell you you're getting close, so hang in there. Once you're in developer mode, you'll need to allow debug over USB. If you can see the developer options, enter the screen and enable USB debugging. If you don't see the developer options, search in your phones settings (not Google search) for Debug, then again simply enable USB Debugging. 

ADB Commands

When we send commands to adb by default, they will route to the first connected device, if we only have one device, then we don't have to specify a serial number to direct the command to.

If however, we have more than one device connected via USB, then we can use the -s <serial number> optional argument.

For example:

adb -s HT4AHJT03522 logcat 

This will send the log request command to the specified serial numbered device.

  • adb shell input keyevent 26 - This will wake up the device from sleep mode.
  • adb devices - List all the connected Android devices serial numbers
  • adb install <filename>.apk - Install the specified package
  • adb uninstall <uri> - Uninstall the application with the specified identifier
  • adb shell am start <full URI of activity you want to run> - Run the specified application on the device, start with the specified activity. For example, com.marcus.app/com.marcus.app.MainActivity
  • adb shell ls - List all files in the root folder on the device
  • adb shell "ls sys" - List all files in the sys folder on the device
  • adb shell "ls -d */" - List only folders on the device in root
  • adb shell "ls -al <folder>"  - List all the info of the folder on the device in root
  • adb shell "ls -al /mnt/shell/emulated/0" - List the contents of the first mounted device, usually SD card 0
  • adb shell "pm list packages" - List all packages installed on the device
  • adb shell "pm list packages | grep com.marcus" - List all packages installed on the device containing the identity com.marcus
  • adb logcat - Start cat'ting the system log file. This process will wait until it is killed (control C) and output every TTY message that is generated on the device

Further Notes

If you want to manipulate the phone from a C# application, then see my other article!

Recently, I also discovered a fantastic project written in Java that allows you to effectively manage your Android device from your PC. You simply connect the PC and Device via USB, and run this Java application. It produces a screen shot of the active device, and converts your mouse events, i.e., click on the screen, down to the device, thus allowing you to remotely interact with your device. This could also be used via remote desktop to control a device on the other side of the planet! Great for remote testing.

That's all, folks!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)