Common commands
Note: "[ip], [package name], [apk path]" and other positions in the text are replaced as a whole.
- Automatically grant all permissions to the app when installing apk
adb shell install -g MyApp.apk
- View connected devices
adb devices
- adb wifi connection (data cable required)
//查看Ip地址
adb shell ifconfig | grep Mask
//设置端口号
adb tcpip 5555
无线连接adb
adb connect [ip]:5555
//断开连接
adb disconnect [ip]:5555
- Install the app
//安装(升级或者同级覆盖安装)
adb install -r [apk路径]
//允许降级安装
adb install -d [apk路径]
- Uninstall app
adb uninstall [包名]
- Clear app cache and data
adb shell pm clear [包名]
- Close the app
adb shell am force-stop [包名]
- Start App -n to specify the complete component name, which is used to specify which Activity to start
adb shell am start -n com.android.settings/.Settings
- List package names can be added | grep xxxx filter or not directly followed by the string to be queried
adb shell pm list packages xxxx
adb shell dumpsys package | grep xxxx
- Find app details and version number
adb shell dumpsys package com.android.settings
adb shell dumpsys package com.android.settings | grep version
- Copy files from device to computer
adb pull [设备里的文件路径] [电脑上的目录]
adb pull data/anr/ /Desktop
- Copy files from computer to device
adb push /Desktop/xxx.png /sdcard/
- Simulate click
adb shell input tap 50 50
- Analog button
adb shell input keyevent [keycode]
keycode | meaning |
---|---|
3 | centered HOME 键 |
4 | return key |
5 | Open the dialer app |
6 | hang up the phone |
24 | Increase volume |
25 | lower the volume |
26 | Power button |
27 | Take a picture (need in the camera application) |
64 | Open browser |
82 | menu |
85 | play / Pause |
86 | Stop play |
87 | Play next song |
88 | Play the previous song |
122 | Move the cursor to the beginning of the line or the top of the list |
123 | Move the cursor to the end of the line or the bottom of the list |
126 | Resume playback |
127 | Pause playback |
164 | Mute |
176 | Open system settings |
187 | Switch app |
207 | Open contact |
208 | Open calendar |
209 | Open music |
210 | Open the calculator |
220 | Decrease screen brightness |
221 | Increase screen brightness |
223 | System hibernation |
224 | Light up the screen |
231 | Turn on the voice assistant |
276 | If there is no wakelock, let the system hibernate |
- Simulated sliding
adb shell input swipe 300 300 500 500
- When in the text box, the text box needs to be focused and can be entered. At this time, you can type text through input
adb shell input text hello
- Log (Note: Under macOS, you need to add double quotation marks to the parameter with * as the tag: W, such as adb logcat ":W", otherwise no matches found: *:W will be reported.)
adb logcat [过滤]
例如: adb logcat ":W"
- Clear log
adb logcat -c
- Get device attribute information (see more information: reference for common commands)
adb shell getprop ro.product.model
- Get device Dpi screen density
adb shell wm density
- Get device screen size (pixels)
adb shell wm size
- Screenshots combined with adb pull can be imported into the computer
//-p 指定保存文件为 png 格式
adb shell screencap -p /sdcard/sc.png
- Screen recording adb pull can be imported into the computer
adb shell screenrecord /sdcard/filename.mp4
- View process
adb shell ps
- View real-time resource usage
adb shell top
- View the process id of an app
adb shell dumpsys package [包名] | grep userId=
- View monkey process ID
adb shell ps | grep monkey
- Kill process
adb shell kill [进程Id]
Common commands reference
Common commands Daquan
Monkey test related commands