Click here to Skip to main content
15,905,607 members
Articles / Mobile Apps / Android
Reference

ADB Common Commands (Android Debug Bridge)

Rate me:
Please Sign up or sign in to vote.
2.40/5 (3 votes)
22 Feb 2016CPOL3 min read 21.6K   5   2
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)


Written By
Technical Lead
Canada Canada
I have a blog here

http://www.electricalengineeringschools.org/blog/

And my robotics web site is here :

http://www.roboticsfordreamers.com/

I have been a software engineer for over 20 years now. I'm an expert in writing scalable restful web API services, which I've been doing for over 7 years now for games companies such as EA and Ubisoft. I've also worked on several video games, including Skate 2 and 3, NHL, Need for Speed, various Assassins Creed games, Far Cry 3 and 4, Driver San Francisco and most recently with a team of 15 on EA's UFC free to play. On this latest project I designed, implemented, tested (including load tests in Gatling and JUnit on AWS), deployed and supported all the web services for the game client, supporting up to a half a million active sessions.

I am proficient at programming in C, C++, C#, Java etc. I've developed many types of games, applications, SDKs and web services in Linux, Unix, iOS, Android and Windows.

My spare time is spent teaching and lecturing computing languages and science. I have a PhD in Artificial Intelligence (specialising in knowledge representation - Semantic networks with inference engines).

Currently I am also building an A.I. general purpose robot. The brains behind it are a mix of 6 Raspberry Pi and Banana Pros, with 2 USB cameras, SATA drive, Router Switch with inter-pi Comms, 2 motorised track systems, plus various sensors including motion/pir/sound etc.

The six pi's are split according to functions, including eyes (image processing/recognition), ears (speech processing and simulated speech),motor (object avoidance, environment mapping, drives all movement), entertainment (web browsing, media playing etc), brain (knowledge system, and adaptive learning/memory systems) and development system ( logging, diagnostics, debugging).

I am available as a consultant, so if you need to get something out the door quick, or want to set down an expandable and resilient framework, ping me !

Comments and Discussions

 
QuestionTypo Pin
Nelek22-Oct-15 21:57
protectorNelek22-Oct-15 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.