ADB command Highlights

Source: Internet
Author: User

What is ADB?

The ADB tool is Android Debug Bridge (Android) tools. It is a command-line window for the computer to interact with the emulator or the real device.
Common operations:

    • Send files to an Android device, or drag files from Android to a local
    • Install/uninstall apps on your Android device
    • Export the app's logs to a local
    • Screen Cutting
      Thinking: What is the difference between the points above that can be substituted in other ways?
How is adb used?
    1. Download the ADB compressed package, unzip, add environment variables, and then can be used in a DOS environment.
    2. USB connects PC and phone, including Android device in normal boot state, USB cable and various interfaces intact.
    3. Android Device developer options and USB debug mode are turned on
    4. The device driver status is normal. This seems to be in Linux and Mac OS X do not worry, under Windows may encounter the need to install the driver, confirm this can right-click "Computer"-"Properties", to " Device Manager to see if there is a yellow exclamation point or question mark on the relevant device, if not, the driver status is OK. Otherwise you can download a mobile helper class program to install the driver first.
    5. Verify the status after connecting the computer and the device via the USB cable.

ADB devices no device: You can check your phone driver with the Driver Wizard and restart your computer after the driver is installed.
ADB devices Unauthorized: Workaround: Remove the USB debug authorization from the developer mode, assistant feature, phone settings, and reopen developer mode

Common command pc linked to all Android devices
adb devices
View ADB version
adb version
Loading package
如果在电脑D盘下面有个a.apk文件,只需要一行命令就安装到手机上:adb install d:/a.apk如果已经安装了这个程序,可以通过以下命令覆盖安装:adb install -r d:/a.apk保留数据和缓存文件,重新安装 apkadb install -r a.apk安装包在android设备中adb shell pm install apk在移动端的路径
Uninstalling packages
adb uninstall 包名卸载软件但是保留配置和缓存文件:adb uninstall -k 包名

If you have more than one emulator or real machine on your machine, you need to specify a specific emulator or a real machine using the-s command line parameter. For example, the following command installs, re-installs, and uninstalls applications on the emulator and the real machine, respectively.

在emulator-5554模拟器上安装ebook.apkadb -s emulator-5554 install ebook.apk在真机上安装ebook.apkadb -s HT9BYL904399 install ebook.apk在emulator-5554模拟器上重新安装ebook.apkadb -s emulator-5554 install -r ebook.apk在真机上重新安装ebook.apkadb -s HT9BYL904399 install -r ebook.apk在emulator-5554模拟器上卸载ebook.apk(不保留数据和缓冲目录)adb -s emulator-5554 uninstall在真机上卸载ebook.apk(保留数据和缓冲目录)adb -s HT9BYL904399 uninstall -k
Package management, how to know an app package name?

The package name in the Android system is a unique identifier for an app, and different apps can have the same name, but the package name cannot be the same.

For example I can build an app myself called "", but my app's package name cannot be (the package name for this), if I specify the package name if also consistent, then my phone only allow to install one of these two apps. Speaking of which many people will have doubts, if someone maliciously made a and the content of the same app, the name and package names and the same, how to tell? Android in order to prevent this, but also made a signature thing, the signature of the general we do not have, so you can sign to identify who the app is.

1、看源代码当有源代码的时候,可以到工程目录下的 “AndroidManifest.xml”文件下查看package这一项。2、adb命令查看列出手机装的所有 app 的包名:adb shell pm list packages 列出系统应用的所有包名:adb shell pm list packages -s 列出除了系统应用的第三方应用包名:adb shell pm list packages -3推测一个包中可能带有的关键字:adb shell dumpsys activity | findstr mFocusedActivity清除应用数据与缓存adb shell pm clear 应用包名
File related
1、接收电脑文件语法:adb push local remote案例:adb push d:/a.txt /sdcard/  把电脑 D 盘下的 a.txt 文件推送到手机 sdcard 目录下2、上传文件到电脑语法:adb pull remote local案例:adb pull /sdcard/a.txt d:/   上传位于/sdcard/目录下的 a.txt 文件到电脑的 D 盘根目录下
Screenshot, Screen recorder
可以在安卓设备上装个QQ之类的软件,进行截屏adb shell screencap /sdcard/a.pngadb shell /system/bin/screencap -p /sdcard/a.png2、使用adb进行屏幕录像adb shell screenrecord /sdcard/a.mp4通过ctrl+c停止录制,你可以在sdcard目录下查看。妈妈再也不担心我到处找录制视频的软件了。
进入shelladb shell退出shellexit
Mobile Information Collection
获取序列号adb get-serialno获取 MAC 地址adb shell  cat /sys/class/net/wlan0/address查看设备型号adb shell getprop ro.product.model查看 Android 系统版本adb shell getprop查看屏幕分辨率adb shell wm size查看屏幕密度adb shell wm density查看permissionsadb shell pm list permissions 查看系统的危险权限dangerous permissionsadb shell pm list permissions -d -g
ADB server kills and starts
adb kill-serveradb start-server比如希望移动adb文件夹,或者adb命令得不到想要的内容时
Related to process:
列出当前进程adb shell ps | findstr 包名杀死某个包的进程adb shell am force-stop 包名
Some performance-related content
获取内存:adb shell dumpsys meminfo 包名获取cpu:adb shell dumpsys cpuinfo | findstr 包名adb shell top -n 1 | findstr 包名获取流畅度相关:adb shell dumpsys gfxinfo 包名
App start-up stops

If you want to run an installed application on a simulator or on a real machine, you can run the program directly, in addition to the operation directly on the emulator or on the real machine, using the following command.

在emulator-5554模拟器上运行ebook.apkadb -s emulator-5554 shell am start -n在真机上运行ebook.apkadb -s HT9BYL904399 shell am start -n其中Main是ebook.apk的主Activity。相当于Windows应用程序的主窗体或Web应用程序的主页面。am是shell命令。
Related to activity operations, etc.
查看当前显示的activityadb shell dumpsys activity | findstr "mFocusedActivity"结果:  mFocusedActivity: ActivityRecord{93a4f9 u0 com.youdao.note/.activity2.MainActivity t36}注意:我们只需要这一部分:com.youdao.note/.activity2.MainActivity即包名+activity  找到当前手机内的top Activity:adb shell dumpsys activity top | findstr ACTIVITY启动某一个Activity:adb shell am start activity路径adb shell am start com.youdao.note/.activity2.MainActivity———————这个Activity路径可通过上面获取top activity的方式获取
See which app is occupied by port 8080 (see local for troubleshooting issues)
netstat -ano|findstr "8080"

ADB command Highlights

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: 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.