[转]Handy adb commands for Android

转自:http://www.growingwiththeweb.com/2014/01/handy-adb-commands-for-android.html

View connected device(s)

Use this to view all connected devices and list their IDs.

adb devices

If multiple devices are attached, use adb -s DEVICE_ID to target a specific device.

Install an application

Use the install command to install an apk, the optional -r argument reinstalls and keeps any data if the application is already installed on the device.

adb install -r APK_FILE

# example
adb install -r ~/application.apk

Uninstall an application

adb uninstall PACKAGE_NAME

# example
adb uninstall com.growingwiththeweb.example

Start an activity

adb shell am start PACKAGE_NAME/ACTIVITY_IN_PACKAGE
adb shell am start PACKAGE_NAME/FULLY_QUALIFIED_ACTIVITY

# example
adb shell am start -n com.growingwiththeweb.example/.MainActivity
adb shell am start -n com.growingwiththeweb.example/com.growingwiththeweb.example.MainActivity

Entering the device’s shell

adb shell

Take a screenshot

Sergei Shvetsov came up with a nice one liner that takes a screenshot withshell screencap and outputs it to a local directory using perl. Checkouthis blog for an explanation.

adb shell screencap -p | perl -pe ‘s/\x0D\x0A/\x0A/g‘ > screen.png

Power button

This command sends the power button event to turn the device on or off.

adb shell input keyevent 26

Unlock screen

This command sends the event that unlocks the lockscreen on the device. It can be combine with the power button command above to turn on and unlock the device.

adb shell input keyevent 82

Print all installed packages

adb shell pm list packages -f

Logging

To show the log stream on your command line.

adb logcat

Filter by tagname

adb logcat -s TAG_NAME
adb logcat -s TAG_NAME_1 TAG_NAME_2

#example
adb logcat -s TEST
adb logcat -s TEST MYAPP

Filter by priority

To show logs of a specific priority warning and above.

adb logcat "*:PRIORITY"

# example
adb logcat "*:W"

Here are the priority levels:

  • V - Verbose (lowest priority)
  • D - Debug
  • I - Info
  • W - Warning
  • E - Error
  • F - Fatal
  • S - Silent (highest priority, on which nothing is ever printed)

Filter by tagname and priority

adb logcat -s TAG_NAME:PRIORITY
adb logcat -s TAG_NAME_1:PRIORITY TAG_NAME_2:PRIORITY

#example
adb logcat -s TEST: W

Filter using grep

Alternatively the output of logcat can be piped to grep on a system that supports it.

adb logcat | grep "SEARCH_TERM"
adb logcat | grep "SEARCH_TERM_1\|SEARCH_TERM_2"

#example
adb logcat | grep "Exception"
adb logcat | grep "Exception\|Error"

Clearing the logcat buffer

Use this to clear the buffer to remove any old log data.

adb logcat -c

Further reading

See more details on the official adb reference site.

时间: 2024-08-29 07:42:38

[转]Handy adb commands for Android的相关文章

Eclipse下ADB报错:Android ADB server didn't ACK,解决办法

转载请注明出处:http://blog.csdn.net/xiaanming/article/details/9401981 ADB server didn't ACK 这个问题会困恼很多的新手朋友,我以前刚开始做Android的时候也遇到过这个问题,不过自己百度,google啥的,也不知道怎么就给解决了,看到群里很多新手朋友都会问这个问题,说实话我也没有一个解决这个问题的终极方法(百试百灵的那种,哈哈),自己没遇到也没有认真的去对待他,今天,就是在今天,我打开Eclipse连上手机,准备调试程

asm.jar使用不了,Error:Could not find adb, please install Android SDK and set path to adb

Error:Could not find adb, please install Android SDK and set path to adb 环境: win7 64bit eclipse 1.4.1 android-sdk_r21-windows 问题描述:将asm.jar放在C盘的用户目录下,执行java -jar asm.jar后,跳出如上提示 原因分析:SDK目录设置不对. 1.SDK环境设置 计算机->属性->高级系统设置->环境变量->系统环境变量 a)新建变量AND

ADB无法找到Android设备

修改adb_usb.ini 在任务管理器中结束adb命令,再对下面的修改(可能产生影响) 在模拟器存放的目录<例如:C:\Documents and Settings\Administrator\.android或当前SDK目录下的.android>下找到或新建一个adb_usb.ini文件,同时增加或写入上面设备的0xVID(VID就是上面的VID_后面跟的数字,例如:0x1782),弄好了再使用重新启动android sdk中的adb就能连接上了 从此不用第三方软件喽! 实测环境:海信平板

转载:Adb远程连接Android系统(通过网络使用ADB(Connect to android with wifi))

本文介绍如何通过网络(尤指无线网络)与Android的adbd进行连接.原理:adb server: 计算机上的一个服务进程,进程名为adbadb daemon: Android 手机上的一个服务进程,进程名为adbdadb client: 你可以认为是计算机上的一个终端窗口,进程名也为adb你的指令通过adb client 交给adb server,server和daemon之间进行通讯.因此,这里建立的连接实际上是server和daemon之间的连接. 有三种方法: 1.到Market搜索W

Linux下adb不能识别Android设备

在Linux中使用adb一直都很顺利,直到前天遇到了小米平板,怎么都没有办法识别,按照google官方http://developer.android.com/tools/device.html的说法去做了,但是还是一点效果都没有,偶然间看到这个帖子http://blog.csdn.net/liuqz2009/article/details/7942569才解决的问题. 解决办法是在$HOME/.android/adb_usb.ini中添加USB的idVendor(厂商号). 如果在$HOME/

Ubuntu 下 使用 adb logcat 显示 Android 日志

作者 : 万境绝尘  转载请著名出处 eclipse 自带的 LogCat 工具太垃圾了, 开始用 adb logcat 在终端查看日志; 1. 解析 adb logcat 的帮助信息 在命令行中输入 adb logcat --help 命令, 就可以显示该命令的帮助信息; [email protected]:~$ adb logcat --help Usage: logcat [options] [filterspecs] options include: -s Set default fil

使用adb命令查看android中的数据库

在采用数据库操作时,经常会出现查询或删除等操作语句执行失败,但是有找不到具体原因.下面将介绍一种命令行方式进行数据库操作,来验证android中的数据库操作语句是否正确等. 具体操作步骤如下: (1)进入到控制台中,输入adb shell,进入到命令模式的环境中: (2)输入命令:cd /data/data/ (3)输入命令:cd com.android.*** ,进入你所在的数据库文件(其中,com.android.***是你的数据库所在文件): (4)可以使用ls -l 命令查看当前目录中的

Android安卓 “adb控件android+sqlite3”

 ADB全称Android Debug Bridge, 是android sdk里的一个工具,用这个工具可以直接操作管理android模拟器或者真实的andriod设备 主要功能有: 1.运行设备的shell(命令行) 2.计算机和设备之间上传/下载文件 3.将本地apk软件安装至模拟器或android设备 ADB是一个 [客户端-服务器端]程序, 1.其中客户端是电脑, 2.服务器端是android设备设备上不需要安装, 只需要在手机上打开选项settings-applications-dev

ADB Not Responding - Android Studio

问题描述: 最近安装了Android Studio v1.0,运行的时候老是这个错误 解决方案: 网上有人说是已经有adb的进程在运行,可是打开任务管理器,找不到对应的adb 进程. 无奈之下,想到adb运行的默认端口是5037, 因此通过命令行 netstat -aon |findstr "5037" 找到了PID,通过PID看到原来是百度自己包装了一个adb(百度手机助手),果断杀掉这个进程,运行android studio,一切恢复正常.