代码改变世界

[转]Handy adb commands for Android

  雪夜&流星  阅读(307)  评论(0编辑  收藏  举报

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

 

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示