Android——Learning Journey: adb common command line

 

Basically, this adb command line is seldom used, and sometimes you have to check it on Baidu when you encounter problems. Today, I will summarize all these materials, and it is convenient for you to look at it yourself.

adb introduction

ADB, Android Debug Bridge, is an irreplaceable and powerful tool for Android developers/testers. adb is a  C/S  command-line tool and a good toy for Android device players. With the help of the adb tool, we can manage the state of the device or phone emulator. You can also perform many mobile phone operations, such as installing software, system upgrades, running shell commands, and so on.

main component

1. Client running on the PC side: it can be used to install, uninstall and debug Android applications

Tools such as ADT in Eclipse, DDMS and Monitor under the SDK Tools directory all use the function of adb to interact with Android devices.

Mobile phone assistants on the PC side, such as 360 mobile phone assistants, Pea pods, Yongyongbao, etc., besides the convenience of installing third-party applications, other functions can basically be completed through the adb command. It is recommended not to install such mobile phones on the computer 测试人员. Assistant, because its built-in adb program may conflict with the adb program under the Android SDK, and 5037 the port is occupied, resulting in the inability to connect to the device when using the adb command

2. Service running on the PC side: it manages the connection of the client to the adb background process on the Android device

      : After the adb service starts, Windows can find the adb.exe process in the task manager

3. The adb background process running on the Android device

       : Execute  adb shell ps | grep adbd , you can find the background process, please use  findstr grep instead of windows

Turn on and off the adb service

  • Close the adb service: adb kill-server
  • Start the adb service: adb start-server

adb kill-server , adb start-server , end adb service, start adb service, usually the two commands are used together

View currently connected devices

adb devices

adb reboot , restart the Android device

 bootloader, restart the device, enter fastboot mode, same as adb reboot-bootloader command

recovery, restart the device, enter recovery mode, students who often flash the machine are more familiar with this mode

get current status

adb get-state , get the status of the device

The status of the device is 3 minutes, device ,  offline ,  unknown

device: the device is connected normally

offline: the connection is abnormal, the device does not respond

unknown: no device is connected

 

Install and uninstall apk program

  • Install apk: adb install <apk_name>
  • Uninstall apk: adb uninstall <apk_name>

 

Upload and download files

  • Upload file: adb push <local file> <remote path>
  • Download file: adb pull <remote file> <local path>

 

Display and export log information

  • Display log: adb logcat
  • Export log information: adb logcat > 1.txt

 

adb get root permission

  • adb executes with root privileges: adb root
  • adb reclaims root privileges: adb unroot

 

Start the adb command line

adb shell

 

adb screenshot and download to computer

adb exec-out screencap -p > picture_name.png

adb shell command

The adb command is some commands that come with the adb program, and the adb shell is the command in the Android system called

Common adb shell commands 

Package Manager , which can be used to get some application information installed on the Android device

pm list package lists the applications installed on the device

Without any options: list all application package names——

adb shell pm list package

-s: list system applications

adb shell pm list package -s 

-3: List third-party apps

adb shell pm list package -3

-f: List the application package name and the corresponding apk name and storage location 

adb shell pm list package -f

-i: List the application package name and its installation source, the result display example:

adb shell pm list package -i

 The displayed result is package:com.zhihu.android installer=com.xiaomi.market

      pm install , install the application

  • pm uninstall , uninstall the application, same as adb uninstall , the following parameters are the package name of the application

  • pm clear , clear application data

  • pm set-install-location , pm get-install-location , set the application installation location and get the application installation location

am

start camera

adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }

stop camera, start again

adb shell am start -S com.android.camera/.Camera
Stopping: com.android.camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER]     cmp=com.android.camera/.Camera }

Guess you like

Origin blog.csdn.net/qq_22576071/article/details/81238960