android開發筆記之ADB Shell Commands

hfreeman2008發表於2016-07-04

這裡寫圖片描述

對於android開發來說,adb shell 命令是我們經常使用的開發命令,下面對這些常用的關鍵adb shell 命令進行一些說明。

adb shell 命令的官方網站

https://developer.android.com/studio/command-line/shell.html#othershellcommands

adb shell 命令的官方網站,如果對於adb shell命令有任何問題,可以去android官網去檢視權威的說明。

Using activity manager (am)

啟動activity

adb shell am start -a android.intent.action.VIEW
adb shell am start  com.example.appinfomanagertinno/.MainActivity

啟動service

adb shell am startservice -a com.lt.test.action.ONESERVICE
adb shell am startservice com.android.music/.MediaPlaybackService

啟動廣播

adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢復出廠設定的方法,會清除記憶體所有內容)
adb shell am broadcast -n com.lt.test/.MyBroadcast

關閉一個應用:

adb shell am force-stop com.example.appinfomanagertinno

關閉所有的後臺程式

adb shell am kill-all

Using package manager (pm)

檢視所有packages:

adb shell pm list packages

檢視特定的packages:

adb shell pm list packages | grep tinno
package:com.applock.tinno
package:com.tinno.simmelock
package:com.tinno.gesture.phone
package:com.tinno.engineermode
package:com.tinno.lanixcodes
package:com.tinno.smartpowersaver
package:com.tinno.gps
package:com.tinno

檢視package的apk位置:

adb shell pm path com.applock.tinno
package:/system/app/applock_tinno/applock_tinno.apk

刪除一個apk:

adb shell pm uninstall com.example.MyApp

檢視所有的features:

adb shell pm  list features

檢視最多支援幾個使用者:

adb shell pm  get-max-users
Maximum supported users: 4

檢視手機上所有的user資訊:

adb shell pm list users

檢視手機所有的permissions:

adb shell pm  list permissions

清除package所有的相關資料:

adb shell pm clear <PACKAGE>

比如清除launcher所有的資料:

adb shell pm clear com.ape.launcher3
Success

手機截圖:

adb shell screencap /sdcard/screen.png

或者:

$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png

手機錄影:

$ adb shell screenrecord /sdcard/demo.mp4

相關文章