Useful ADB commands

Pradeep Deshmukh
4 min readNov 30, 2020

--

For increasing development productivity every android developer should use adb commands. It gives good control on development environment and we can take it’s advantage in debugging. So lets begin…… :)

Basic Usage

adb basic syntax of the command

adb [-d|-e|-s <serialNumber>] <command>

If only one device / emulator connection, you can omit the [-d | -e | -s <serialNumber>] this part, the direct use adb <command>

But in case you are using multiple devices the use the options:

  • [-d ] use when you want to run the command only on device which is connected with USB.
  • [-e] use when you want to run the command only on emulator
  • [-s <serial number>] use when you want to run on specific device give the serial number of device/emulator.

To see the serial numbers of connected devices adb devices is the command, this will return the list of devices connected with it’s serial numbers.

  1. Screen Resolution :

adb shell wm size : Returns the screen resolution

2. Start/Stop:

adb start-server : To start the server by default it is executed first time

adb kill-server : To stop server

3. View adb version:

adb version : Returns of current adb version number.

4. Run adbd as root: The operating principle is adb adb server daemon and the phone side PC side adbd establish a connection, then the PC side adb client via adb server forward command parsing after running adbd receive commands.

So if adbd ordinary rights to perform some require root privileges to execute the command can not be directly used adb xxx execution. Then you can then execute the command adb shell aftersu, but also allows adbd root privileges to perform this high privilege can execute arbitrary commands.

command : adb root

output: restarting adbd as root

Now run adb shell, take a look at the command line prompt is not turned into a #?

After some phone root can not let adbd by adb root execute commands with root privileges, some models such as Samsung, will be prompted toadbd can not run as root in production builds, then you can install adbd Insecure, then adb root try.

Accordingly, if you want to restore adbd non-root privileges, you can use adb unroot command.

5. Designated adb server network port:

command: adb -P <port> start-server

The default port is 5037.

6. USB connection: it’s use is to ensure the hardware is connected

command: adb devices

7. Wireless connection: In addition to the USB connection to the computer to use adb, can also be a wireless connection, although the connection process is also step using USB needs, but after a successful connection to your device can get rid of the limit of the USB cable within a certain range it !

Steps:

  1. Connect Android device to run adb computer connected to the same local area network, such as connected to the same WiFi.
  2. The device connected to the computer via a USB cable.

Make sure the connection is successful (you can run adb devices see if you can list the device).

Allow the device listens on port 5555 TCP / IP connections:

adb tcpip 5555

Find the IP address of the device. Generally the ‘Settings’ in — “About phone” — “state information” — “IP address” is found. Connect the device via IP address.

adb connect <device-ip-address>

To making sure the connection is stablished you can use the connection command. adb devices and you will see the connected device information.

8. Application Management: To get information about installed applications on the device:

  • Display all applications: adb shell pm list packages
  • Display system applications: adb shell pm list packages -s
  • Third party usage: adb shell pm list packages -3
  • Application package name containing string :

adb shell pm list packages <string_that_contains>

9. Install apk: To install apk on the targeted device

adb install [-lrtsdg] <path_to_apk>

  • -l : Will be applied to protect the installation directory / mnt / asec
  • -r : Allowed to cover the installation
  • -t : Allowed to install application specified in AndroidManifest.xml android: testOnly =" true " Application
  • -s : Install apps to sdcard
  • -d : Downgrade coverage allows installation
  • -g : Grant all runtime permission. “This is my all time favourite” :)

10. Uninstalling: adb uninstall [-k] <packagename>

  • k : this is optional, it uninstall the application but keep the data and cache directory.

11. Clear app cache data: adb shell pm clear <packagename>

12. View Reception activity: To get which application is on foreground or on focus.

adb shell dumpsys activity activities | grep mFocusedActivity

13. View running all services:

adb shell dumpsys activity services [<packagename

<packagename> parameter is optional, command with <packagename> will output services related with that packagename, and command without <packagename> will output all services.

14. Application package detail information:

adb shell dumpsys package <packagename>

There are many infos in output, include Activity Resolver Table, Registered ContentProviders, package name, userId, files/resources/codes path after install, version name and code, permissions info and their granted status, signing version, etc.

15. Launch app:

adb shell am start [option <INTENT>

e.g : adb shell am start -n org.mazhuang.boottimemeasure/.MainActivity.

TO BE CONTINUED… :) I will keep adding more useful commands based on my new experience with the commands.

--

--

Pradeep Deshmukh
Pradeep Deshmukh

Written by Pradeep Deshmukh

Programming lover, like to write Good quality code, code should be easy to understandable by humans

No responses yet