ADB, or Android Debug Bridge, is an irreplaceable and powerful tool for Android developers/testers.
The connection between adb and application
1. Start/stop
Start the adb server command:
adb start-server
(Generally, there is no need to execute this command manually. If you find that the adb server is not started when running the adb command, it will be automatically called.)
Stop the adb server command:
adb kill-server
2. Check the adb version
Order:
adb version
The output is:
C:\WINDOWS\system32>adb version
Android Debug Bridge version 1.0.41
Version 29.0.6-6198805
Installed as E:\program\android-sdk_r24.4.1-windows\android-sdk-windows\platform-tools\
3. Check connected devices
adb devices
The output is:
C:\WINDOWS\system32>adb devices
List of devices attached
CVH7N16A12000234 device
Display parameters
1.android_id
adb shell settings get secure android_id
System version
adb shell getprop
3. Resolution
adb shell wm size
The output is:
C:\WINDOWS\system32>adb shell wm size
Physical size: 1440x2560
4. Density
adb shell wm density
The output is:
Physical density: 560
5. Display parameters
adb shell dumpsys window displays
where mDisplayId is the display number, init is the initial resolution and screen density, and the height of the app is smaller than that init, indicating that there are virtual buttons at the bottom of the screen.
Adb interacts with the application
1. Check the front desk Activity
adb shell dumpsys activity | findstr "mFocusedActivity"
Get the full path:
adb shell dumpsys window | findstr mCurrentFocus
2. View running services
adb shell dumpsys activity services [packagename]
3View application details
adb shell dumpsys package [packagename]
command | use |
---|---|
start [options] | Start Activity |
startservice [options] | Start Service |
broadcast [options] | Send a broadcast |
force-stop | Stop the process |
The options used to determine the intent object are as follows:
parameter | effect |
---|---|
-a | Specify an action, such as |
-c | Specify category, such as .APP_CONTACTS |
-n | Specify the full component name to specify which Activity to start, such as /.ExampleActivity |
-W | Output the complete open application process |
The am (Activity Manager) command is to start an APP, start Activity, start broadcasting and services, etc.
4. Start the application
adb shell am start xx
For example:
C:\WINDOWS\system32>adb shell am start -W / Starting: Intent { act= cat=[] cmp=/. } Warning: Activity not started, its current task has been brought to the front Status: ok Activity: /. ThisTime: 2916 TotalTime: 2916 WaitTime: 2936 Complete
5. Start Service
adb shell am startservice "/"
6. Stop Service
adb shell am stopservice [options] <INTENT>
7. Send broadcast
adb shell am broadcast -a ""
8. Forced stop application
adb shell am force-stop com.
9. Check the application installation path
adb shell pm path (PACKAGE)
For example:
C:\WINDOWS\system32>adb shell pm path package:/data/app/-xt0XnDpe7yq8Z5YGef0iEA==/
10. Check mobile apps
adb shell pm list packages
You can add some parameters to filter to view different lists based on adb shell pm list packages. The supported filter parameters are as follows:
parameter | Show list |
---|---|
none | All Applications |
-f | Display the app-associated apk file |
-d | Only displayed disabled applications |
-e | Only enabled applications are displayed |
-s | Show only system applications |
-3 | Show only third-party applications |
-i | Show the installer of the application |
-u | Includes uninstalled apps |
For example:
1. Print a list of third-party applications
adb shell pm list package -3
The output is:
C:\WINDOWS\system32>adb shell pm list package -3
package:
package:
package:
package:
package:
package:
package:
package:
package:.freefast_ipchanger
package:
package:
package:
package:
package:
package:
package:
package:
package:
package:
2. Applications with a package name containing a certain character
C:\WINDOWS\system32>adb shell pm list packages tencent package: package:.qqlivei18n package:
Of course, you can also use pipe characters to filter:
C:\WINDOWS\system32>adb shell pm list packages | findstr tencent package: package:.qqlivei18n package:
11. Install apk
adb install
Allow overwrite installation:
adb install -r
12. Uninstall apk
adb uninstall
Uninstall and retain data:
adb uninstall -k
13. Specify the network port of adb server
adb -P <port> start-server
File Management
1. Copy the files in the device to the computer
adb pull <File path in the device> [Directory on the computer]
The directory parameters on the computer can be omitted and copied to the current directory by default.
2. Copy the files from the computer to the device
adb push <File path on the computer> <Directory in the device>
Event input
1. Simulate key operation
adb shell input keyevent < keycode >
Different keycodes can implement different functions, the list is as follows:
keycode: meaning 3 HOME key 4 返回key 5 Open the dial app 6 Hang up the phone 24 Increase the volume 25 Reduce the volume 26 电源key 27 Photograph(Need in the camera application) 64 Open a browser 82 菜单key 85 Play/pause 86 停止Play 87 Play下一首 88 Play上一首 122 Move the cursor to the first line or the top of the list 123 Move the cursor to the end of the line or the bottom of the list 126 恢复Play 127 pausePlay 164 Mute 176 Open System Settings 187 Switch app 207 Open a contact 208 Open the calendar 209 Turn on the music 210 Open the calculator 220 Reduce screen brightness 221 Improve screen brightness 223 System sleep 224 Light up the screen 231 Turn on the voice assistant 276 If not wakelock 则让System sleep
Turn on and turn off the screen:
adb shell input keyevent 26
2. Slide the screen
adb shell input swipe x1 y1 x2 y2
Parameters represent: starting point x coordinate, starting point y coordinate, end point x coordinate, end point y coordinate
3. Enter text
adb shell input text 123
4. Simulate screen click event
adb shell input tap 500 500
Event output
1. Log information:
useadb logcatCan display log information
:
The dumpsys command can provide a lot of system information. You can view dumpsys services that can provide query information through the adb shell service list.
To list a few:
View battery information
adb shell dumpsys battery
Check alarm clock information
adb shell dumpsys alarm
3. Screenshot
adb shell screencap /imgpath/
4. Screen recording
adb shell screenrecord /imgpath/demo.mp4
imgpath can be obtained based on the photo path information in your album
The above is a detailed explanation of the common usage of Android adb. For more information about the usage of Android adb, please follow my other related articles!