Android Common ADB Command summary

Source: Internet
Author: User

Recent "Jump" comparison of fire, saw a brush sub-auxiliary with the ADB + python, so to learn the use of ADB.

The following are transferred from Chung and

For mobile Android testing, the ADB command is a very important point, you must memorize the usual ADB commands in the heart, will be a great convenience for Android testing, many of the commands will be used in automated test scripts.

Android Debug Bridge

ADB is actually Android Debug Bridge , the abbreviation of Android Debug Bridge, ADB is a C/s Architecture command-line tool, mainly consists of 3 parts:

    • Client running on PC: it can install, uninstall, and debug Android apps.
    • Service running on the PC side: its management client connects to the ADB background process on the Android device
    • The ADB background process running on Android devices
ADB command

In the process of development or testing, we can manage multiple devices through the ADB in the general format of:

adb [-e |-D |-s < device serial number;] < sub-command >

With the environment variables in place, enter ADB help in the command window or enter ADB directly, and all the option descriptions and subcommands will be listed.

Here are some of the commands that are commonly used:

    • ADB devices, get device list and device status

[xuxu:~]$ adb devices List of devices attached 44c826a0 device

    • ADB get-state, getting the status of the device

[xuxu:~]$ adb get-state device

The state of the device is 3 minutes, and, device offlineunknown

Device: normal connection of devices

Offline: Connection unexpected, device not responding

Unknown: No device connected

    • ADB kill-server, adb start-server, end adb service, start adb service, usually two command

Generally in connection with an exception, use ADB devices not properly list the device, device status is abnormal when using kill-server, and then run Start-server to restart the service

    • ADB logcat, print system logs for Android

    • ADB bugreport, prints the output of Dumpsys, Dumpstate, Logcat, and is also used for parsing errors

More output, recommended redirection to a file

adb bugreport > d:\bugreport.log

    • ADB install, installation application, overwrite installation is using the-r option

If you need to install the APK with Chinese name in Windows, you need to change the ADB, Baidu can find the ADB to make changes, support the Chinese command apk, please search by yourself

    • ADB Uninstall, uninstall the app, followed by the parameter is the app's package name, please distinguish it from the APK file name

'-K ' means keep the data and the cache directories,-k option, saving the database and caching directory when uninstalling

    • ADB pull to copy files or folders on your Android device to a local

For example, copy the Pull.txt file under SDcard to the D drive:

adb pull sdcard/pull.txt d:\

If you need to rename to Rename.txt:

adb pull sdcard/pull.txt d:\rename.txt

Note the permissions, copy the system permissions in the directory of the file, requires root, and the general Android root can not use the command to copy, and need to use a similar to the RE-file browser on the phone, the system's file system is mounted to read and write, before the mobile system files on the phone copy , it is recommended to use the development version of Xiaomi Mobile phone, Iuni is also good drop ~ ~

    • ADB push, push local files to Android device
      For example, push the push.txt to SDcard under the D drive:

adb push d:\push.txt sdcard/

There is no less slash behind the SDcard, or the following error will occur:

[xuxu:~]$ adb push push.txt sdcard failed to copy ‘push.txt‘ to ‘sdcard‘: Is a directory

Permissions issue with pull command

    • ADB root, adb remount, is only useful for phones similar to the Xiaomi development version, you can directly have these two commands to get root permissions and mount the system file system as read-write status

    • ADB reboot, restart Android device

bootloader, restart device, enter FastBoot mode, with ADB reboot-bootloader command
Recovery, restart the device, enter the recovery mode, often brush the students more familiar with this mode

    • ADB forward, redirecting a port on a host to a port on the device

adb forward tcp:1314 tcp :8888

After executing this command, all messages sent to host port 1314 will be forwarded to the 8888 port on the Android device, so you can control the Android device remotely.

    • ADB connect remote Connect Android device
ADB shell command

Here are some common adb shell commands (where PM, am commands are large and use level four headings)

Pm

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

    • PM List package Lists the apps installed on the device

Without any options: List all the app's package names (don't know how to find the app's package name for the classmates to see here)

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 app package name and the corresponding APK name and storage location

adb shell pm list package -f

-I: Lists the app package names and their installation sources, showing examples of the results:
package:com.zhihu.android installer=com.xiaomi.market

adb shell pm list package -i

Command Add filter: Filter keyword, can easily find the application you want

parameter combinations, for example, to find 知乎 the package name in a three-party app, the APK storage location, the installation source:

[xuxu:~]$ adb shell pm list package -f -3 -i zhihu package:/data/app/com.zhihu.android-1.apk=com.zhihu.android installer=com.xiaomi.market

    • PM Path lists the. apk location for the corresponding package name

[xuxu:~]$ adb shell pm path com.tencent.mobileqq package:/data/app/com.tencent.mobileqq-1.apk

    • PM List instrumentation, listing applications with unit test case, followed by parameter-F (as in the PM list package), and [Target-package]

    • PM dump, followed by the package name, lists the dump information for the specified app, with a variety of information and self-viewing

adb shell pm dump com.tencent.mobileqq

    • PM install, installing the app

The target apk is stored on the PC side, please install it with ADB installation
Target apk is stored on Android device, please install it with PM install

    • PM Uninstall, uninstall the application, with ADB uninstall, followed by the parameters are the package name of the app

    • PM clear, Erase app data

    • PM Set-install-location, PM get-install-location, set app install location, get app install location

[0/auto]: Default is Auto
[1/internal]: default is installed inside the phone
[2/external]: Default installation on external storage

Am

It's a huge order again.

    • Am Start, start an Activity, started the system camera application as an example

Start the camera

[xuxu:~]$ adb shell am start -n com.android.camera/.Camera Starting: Intent { cmp=com.android.camera/.Camera }

Stop the target app before starting

[xuxu:~]$ 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 }

Wait for the app to finish booting

[xuxu:~]$ adb shell am start -W com.android.camera/.Camera Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera } Status: ok Activity: com.android.camera/.Camera ThisTime: 500 TotalTime: 500 Complete

Start a default browser to open a Web page

[xuxu:~]$ adb shell am start -a android.intent.action.VIEW -d http://testerhome.com Starting: Intent { act=android.intent.action.VIEW dat=http://testerhome.com }

Start Dialer Dial 10086

[xuxu:~]$ adb shell am start -a android.intent.action.CALL -d tel:10086 Starting: Intent { act=android.intent.action.CALL dat=tel:xxxxx }

    • Am instrument, start a instrumentation, unit test or Robotium will use

    • Am monitor, monitor crash and ANR

[xuxu:~]$ adb shell am monitor Monitoring activity manager... available commands: (q)uit: finish monitoring ** Activity starting: com.android.camera

    • Am Force-stop, followed by package name, end application

    • Am StartService, start a service

    • AM broadcast, send a broadcast

Input

This command can send key events to Android devices

    • Input text, send textual content, cannot send Chinese

adb shell input text test123456

If you first set the keyboard to an English keyboard

    • Input keyevent, Send key event, Keyevent.java

adb shell input keyevent KEYCODE_HOME

Analog Press the Home button, the source code is defined:
public static final int keycode_home = 3;
Therefore, you can replace the command with the KEYCODE_HOME3

    • Input tap, sends a touch event to the screen

adb shell input tap 500 500

Click on the screen where coordinates are 500 500

    • Input swipe, sliding event

adb shell input swipe 900 500 100 500

Swipe the screen from right to left
If the version is not less than 4.4, you can simulate long-press events

adb shell input swipe 500 500 501 501 2000

In fact, in a small distance, in a longer duration of the slide, and finally show the result is the long press action

Here you will find that what Monkeyrunner can do, through the ADB command, can be done, if encapsulated, will do better than MR.

Screencap

Command

adb shell screencap -p /sdcard/screen.png

Screenshot, save to SDcard directory

Wm
[xuxu:~]$ adb shell wm sizePhysical size: 1080x1920  

Get Device resolution

Log

This command is very interesting, you can print the information you set in the Logcat, the specific use of their own thinking!

adb shell log -p d -t xuxu "test adb shell log"

-P: Priority,-t:tag, tag, followed by message

[xuxu:~]$ adb logcat -v time -s xuxu               --------- beginning of /dev/log/system--------- beginning of /dev/log/main05-15 13:57:10.286 D/xuxu    (12646): test adb shell log  
Getprop

View the parameter information of the Android device, run only, and the result is displayed as a adb shell getprop key : value key-value pair, such as to get the value of a key:

adb shell getprop ro.build.version.sdk

Get the SDK version of the device

Android Common ADB Command summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.