Android adb shell后面可用的常用命令详细列举

Posted King-Guo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android adb shell后面可用的常用命令详细列举相关的知识,希望对你有一定的参考价值。

adb shell 后面可以跟的常见命令有如下:
am app_process backup bootanimation coloradjust dpm idmap input media requestsync settings svc uiautomator
appops appwidget bmgr bu content hid ime interrupter pm screencap sm telecom wm
dumpsys logcat getprop reboot 

下面讲述一些常用的命令

一 adb shell pm 常用命令

zhanghu@winth:~$ adb shell
root@wt89536:/ # pm
usage: pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER]
pm list permission-groups
pm list permissions [-g] [-f] [-d] [-u] [GROUP]
pm list instrumentation [-f] [TARGET-PACKAGE]
pm list features
pm list libraries
pm list users
pm path PACKAGE
pm dump PACKAGE
pm install [-lrtsfd] [-i PACKAGE] [--user USER_ID] [PATH]
pm install-create [-lrtsfdp] [-i PACKAGE] [-S BYTES]
[--install-location 0/1/2]
[--force-uuid internal|UUID]
pm install-write [-S BYTES] SESSION_ID SPLIT_NAME [PATH]
pm install-commit SESSION_ID
pm install-abandon SESSION_ID
pm uninstall [-k] [--user USER_ID] PACKAGE
pm set-installer PACKAGE INSTALLER
pm move-package PACKAGE [internal|UUID]
pm move-primary-storage [internal|UUID]
pm clear [--user USER_ID] PACKAGE
pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
pm disable-user [--user USER_ID] PACKAGE_OR_COMPONENT
pm disable-until-used [--user USER_ID] PACKAGE_OR_COMPONENT
pm hide [--user USER_ID] PACKAGE_OR_COMPONENT
pm unhide [--user USER_ID] PACKAGE_OR_COMPONENT
pm grant [--user USER_ID] PACKAGE PERMISSION
pm revoke [--user USER_ID] PACKAGE PERMISSION
pm reset-permissions
pm set-app-link [--user USER_ID] PACKAGE always|ask|never|undefined
pm get-app-link [--user USER_ID] PACKAGE
pm set-install-location [0/auto] [1/internal] [2/external]
pm get-install-location
pm set-permission-enforced PERMISSION [true|false]
pm trim-caches DESIRED_FREE_SPACE [internal|UUID]
pm create-user [--profileOf USER_ID] [--managed] USER_NAME
pm remove-user USER_ID
pm get-max-users

pm list packages: prints all packages, optionally only
those whose package name contains the text in FILTER. Options:
-f: see their associated file.
-d: filter to only show disbled packages.
-e: filter to only show enabled packages.
-s: filter to only show system packages.
-3: filter to only show third party packages.
-i: see the installer for the packages.
-u: also include uninstalled packages.

pm list permission-groups: prints all known permission groups.

pm list permissions: prints all known permissions, optionally only
those in GROUP. Options:
-g: organize by group.
-f: print all information.
-s: short summary.
-d: only list dangerous permissions.
-u: list only the permissions users will see.

pm list instrumentation: use to list all test packages; optionally
supply <TARGET-PACKAGE> to list the test packages for a particular
application. Options:
-f: list the .apk file for the test package.

pm list features: prints all features of the system.

pm list users: prints all users on the system.

pm path: print the path to the .apk of the given PACKAGE.

pm dump: print system state associated with the given PACKAGE.

pm install: install a single legacy package
pm install-create: create an install session
-l: forward lock application
-r: replace existing application
-t: allow test packages
-i: specify the installer package name
-s: install application on sdcard
-f: install application on internal flash
-d: allow version code downgrade
-p: partial application install
-g: grant all runtime permissions
-S: size in bytes of entire session

pm install-write: write a package into existing session; path may
be '-' to read from stdin
-S: size in bytes of package, required for stdin

pm install-commit: perform install of fully staged session
pm install-abandon: abandon session

pm set-installer: set installer package name

pm uninstall: removes a package from the system. Options:
-k: keep the data and cache directories around after package removal.

pm clear: deletes all data associated with a package.

pm enable, disable, disable-user, disable-until-used: these commands
change the enabled state of a given package or component (written
as "package/class").

pm grant, revoke: these commands either grant or revoke permissions
to apps. The permissions must be declared as used in the app's
manifest, be runtime permissions (protection level dangerous),
and the app targeting SDK greater than Lollipop MR1.

pm reset-permissions: revert all runtime permissions to their default state.

pm get-install-location: returns the current install location.
0 [auto]: Let system decide the best location
1 [internal]: Install on internal device storage
2 [external]: Install on external media

pm set-install-location: changes the default install location.
NOTE: this is only intended for debugging; using this can cause
applications to break and other undersireable behavior.
0 [auto]: Let system decide the best location
1 [internal]: Install on internal device storage
2 [external]: Install on external media

pm trim-caches: trim cache files to reach the given free space.

pm create-user: create a new user with the given USER_NAME,
printing the new user identifier of the user.

pm remove-user: remove the user with the given USER_IDENTIFIER,
deleting all data associated with that user

 

1. 查看系统中是否安装了指定包名的应用

A:
root@wt89536:/ # pm list packages com.android.settings
package:com.android.settings
root@wt89536:/ # 
表明包名为com.android.settings的应用已经安装在系统中

B:
root@wt89536:/ # pm list packages com.test.test 
root@wt89536:/ # 
输入pm list packages com.test.test 之后没有任何输出,表明该应用未安装在系统中

C:
查看安装的路径及apk名字和对应的包名:
root@wt89536:/ # pm list packages -f |more 
package:/system/app/lingxi_v3.0.2230_16015906_160418/lingxi_v3.0.2230_16015906_1
60418.apk=com.iflytek.cmcc
package:/system/app/SampleExtAuthService/SampleExtAuthService.apk=com.qualcomm.q
ti.auth.sampleextauthservice
package:/data/app/IndonesianPack/IndonesianPack.apk=com.cootek.smartinputv5.lang
uage.indonesian
package:/system/app/OmaDownload/OmaDownload.apk=com.qrd.omadownload
package:/data/app/VietnamPack/VietnamPack.apk=com.cootek.smartinputv5.language.v
ietnam
package:/system/priv-app/TelephonyProvider/TelephonyProvider.apk=com.android.pro
viders.telephony
package:/data/app/CangjiePack/CangjiePack.apk=com.cootek.smartinputv5.language.c
angjie
package:/system/priv-app/CalendarProvider/CalendarProvider.apk=com.android.provi
ders.calendar
package:/system/priv-app/MediaProvider/MediaProvider.apk=com.android.providers.m
edia
package:/system/vendor/app/colorservice/colorservice.apk=com.qti.service.colorse
rvice
package:/system/app/Emailactivation/Emailactivation.apk=cn.richinfo.automail
package:/system/app/ModemTestMode/ModemTestMode.apk=com.qualcomm.qti.modemtestmo
de
package:/system/app/shutdownlistener/shutdownlistener.apk=com.qualcomm.shutdownl
istner
package:/system/priv-app/WallpaperCropper/WallpaperCropper.apk=com.android.wallp
apercropper
package:/system/priv-app/CNEService/CNEService.apk=com.quicinc.cne.CNEService
package:/data/app/com.goodix.fpsetting-1/base.apk=com.goodix.fpsetting
package:/system/app/ProfileMgr/ProfileMgr.apk=com.android.profile
--More--

 

2. 查看指定包名的安装路径

root@wt89536:/ # pm path com.android.settings 
package:/system/priv-app/Settings/Settings.apk
root@wt89536:/ # 
 

3.dump已经安装的所用应用的信息,包括所有类名

root@wt89536:/ #pm dump PACKAGE 

过滤输出指定应用,如:
root@wt89536:/ # 
root@wt89536:/ # pm dump PACKAGE |grep "com.android.fingerprint" |more 
74feecb com.android.fingerprint/.FingerpintApplyGuide
com.android.fingerprint
[com.android.fingerprint]
Package [com.android.fingerprint] (e0b109f):
pkg=Package3c0b5ec com.android.fingerprint
applicationInfo=ApplicationInfo1038db5 com.android.fingerprint
dataDir=/data/user/0/com.android.fingerprint
70/1/2 上午2:36: System package com.android.fingerprint no longer exists; wi
ping its data
package=com.android.fingerprint totalTime="1:14:53" lastTime="2016/1/1 
上午10:10" lastTimeSystem="2016/1/1 上午10:10" inactiveTime="18:28" 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:00" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:00" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerprintManageBoard 
time="2016/1/1 上午8:00" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerprintManageBoard 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerprintRenameBoard 
time="2016/1/1 上午8:00" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerprintRenameBoard 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:00" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:01" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:01" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:01" type=MOVE_TO_BACKGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:01" type=MOVE_TO_FOREGROUND package=com.android.f
ingerprint class=com.android.fingerprint.FingerpintApplyGuide 
time="2016/1/1 上午8:01" type=MOVE_TO_BACKGROUND package=com.android.f
....

 

4.launcher上是否显示指定应用

root@wt89536:/ # pm enable com.android.fingerprint 
Package com.android.fingerprint new state: enabled

root@wt89536:/ # pm unhide com.android.fingerprint 
Package com.android.fingerprint new hidden state: false



root@wt89536:/ # pm disable com.android.fingerprint 
Package com.android.fingerprint new state: disabled

root@wt89536:/ # pm hide com.android.fingerprint 
Package com.android.fingerprint new hidden state: true


通过上面这种方式可以查看Pm.java源码,获知怎样隐藏一个apk
 

5.清除应用数据

root@wt89536:/ # pm clear com.android.fingerprint 
Success
root@wt89536:/ # 
 

6.查看系统apk的包名

zhanghu@winth:~$ adb shell pm list packages -s
 

7.查看第三方apk包名

zhanghu@winth:~$ adb shell pm list packages -3
package:com.android.touchtest
 

二 dump系统框架service信息

2.1 查看可以dump的系统框架service

adb shell dumpsys |grep "DUMP OF SERVICE"
或adb shell dumpsys -l(字母l)

zhanghu@winth:~$ adb shell dumpsys |grep "DUMP OF SERVICE"
120:DUMP OF SERVICE AtCmdFwd:
122:DUMP OF SERVICE DockObserver:
128:DUMP OF SERVICE SurfaceFlinger:
346:DUMP OF SERVICE accessibility:
353:DUMP OF SERVICE account:
371:DUMP OF SERVICE activity:
14692:DUMP OF SERVICE alarm:
15056:DUMP OF SERVICE android.hardware.fingerprint.IFingerprintDaemon:
15059:DUMP OF SERVICE android.security.keystore:
15061:DUMP OF SERVICE android.service.gatekeeper.IGateKeeperService:
15063:DUMP OF SERVICE appops:
15551:DUMP OF SERVICE appwidget:
15619:DUMP OF SERVICE audio:
15733:DUMP OF SERVICE backup:
15861:DUMP OF SERVICE battery:
15876:DUMP OF SERVICE batteryproperties:
15882:DUMP OF SERVICE batterystats:
20123:DUMP OF SERVICE bluetooth_manager:
20132:DUMP OF SERVICE carrier_config:
20141:DUMP OF SERVICE clipboard:
20143:DUMP OF SERVICE cneservice:
20145:DUMP OF SERVICE com.qualcomm.location.izat.IzatService:
20147:DUMP OF SERVICE com.qualcomm.qti.qseeproxy:
20149:DUMP OF SERVICE commontime_management:
20152:DUMP OF SERVICE connectivity:
20226:DUMP OF SERVICE consumer_ir:
20228:DUMP OF SERVICE content:
20584:DUMP OF SERVICE country_detector:
20586:DUMP OF SERVICE cpuinfo:
20669:DUMP OF SERVICE dbinfo:
22305:DUMP OF SERVICE device_policy:
22339:DUMP OF SERVICE deviceidle:
22381:DUMP OF SERVICE devicestoragemonitor:
22391:DUMP OF SERVICE diskstats:
22397:DUMP OF SERVICE display:
22400:DUMP OF SERVICE display.qservice:
22402:DUMP OF SERVICE dpmservice:
22404:DUMP OF SERVICE dreams:
22430:DUMP OF SERVICE drm.drmManager:
22432:DUMP OF SERVICE dropbox:
22999:DUMP OF SERVICE ethernet:
23016:DUMP OF SERVICE extphone:
23018:DUMP OF SERVICE fingerprint:
23021:DUMP OF SERVICE gbahttpauth:
23023:DUMP OF SERVICE gfxinfo:
23858:DUMP OF SERVICE goodix.fp:
23888:DUMP OF SERVICE graphicsstats:
24033:DUMP OF SERVICE imms:
24035:DUMP OF SERVICE ims:
24037:DUMP OF SERVICE input:
24497:DUMP OF SERVICE input_method:
24697:DUMP OF SERVICE iphonesubinfo:
24699:DUMP OF SERVICE isms:
24701:DUMP OF SERVICE isub:
25220:DUMP OF SERVICE jobscheduler:
25264:DUMP OF SERVICE launcherapps:
25266:DUMP OF SERVICE location:
25315:DUMP OF SERVICE lock_settings:
25317:DUMP OF SERVICE mdtp:
25319:DUMP OF SERVICE media.audio_flinger:
25620:DUMP OF SERVICE media.audio_policy:
26136:DUMP OF SERVICE media.camera:
26363:DUMP OF SERVICE media.camera.proxy:
26365:DUMP OF SERVICE media.player:
26372:DUMP OF SERVICE media.radio:
26374:DUMP OF SERVICE media.resource_manager:
26409:DUMP OF SERVICE media.sound_trigger_hw:
26411:DUMP OF SERVICE media_projection:
26416:DUMP OF SERVICE media_router:
26464:DUMP OF SERVICE media_session:
26508:DUMP OF SERVICE meminfo:
29520:DUMP OF SERVICE midi:
29525:DUMP OF SERVICE mount:
29571:DUMP OF SERVICE netpolicy:
29609:DUMP OF SERVICE netstats:
29697:DUMP OF SERVICE network_management:
29878:DUMP OF SERVICE network_score:
29881:DUMP OF SERVICE notification:
30178:DUMP OF SERVICE package:
46276:DUMP OF SERVICE permission:
46278:DUMP OF SERVICE persistent_data_block:
46280:DUMP OF SERVICE phone:
46282:DUMP OF SERVICE power:
46284:DUMP OF SERVICE powerguru:
46286:DUMP OF SERVICE print:
46302:DUMP OF SERVICE processinfo:
46304:DUMP OF SERVICE procstats:
55753:DUMP OF SERVICE qti.ims.connectionmanagerservice:
55755:DUMP OF SERVICE restrictions:
55757:DUMP OF SERVICE rttmanager:
55759:DUMP OF SERVICE samplingprofiler:
55763:DUMP OF SERVICE scheduling_policy:
55765:DUMP OF SERVICE search:
55784:DUMP OF SERVICE sensorservice:
55902:DUMP OF SERVICE serial:
55904:DUMP OF SERVICE servicediscovery:
55909:DUMP OF SERVICE simphonebook:
55911:DUMP OF SERVICE sip:
55913:DUMP OF SERVICE statusbar:
55945:DUMP OF SERVICE telecom:
55978:DUMP OF SERVICE telephony.registry:
56046:DUMP OF SERVICE textservices:
56130:DUMP OF SERVICE trust:
56137:DUMP OF SERVICE uimode:
56145:DUMP OF SERVICE updatelock:
56148:DUMP OF SERVICE usagestats:
56364:DUMP OF SERVICE usb:
56386:DUMP OF SERVICE user:
56392:DUMP OF SERVICE vendor.qcom.PeripheralManager:
56394:DUMP OF SERVICE vibrator:
56418:DUMP OF SERVICE voiceinteraction:
56462:DUMP OF SERVICE wallpaper:
56475:DUMP OF SERVICE webviewupdate:
56477:DUMP OF SERVICE wifi:
57921:DUMP OF SERVICE wifip2p:
57951:DUMP OF SERVICE wifiscanner:
58051:DUMP OF SERVICE window:
 

2.2 查看当前设备的分辨率信息

命令:adb shell dumpsys deviceidle |grep "DisplayMetrics"

zhanghu@winth:~$ adb shell dumpsys deviceidle |grep "DisplayMetrics"
33: mCurDisplay=Display id 0: DisplayInfo"Built-in Screen", uniqueId "local:0", app 1080 x 1920, real 1080 x 1920, largest app 1920 x 1845, smallest app 1080 x 1005, mode 1, defaultMode 1, modes [id=1, width=1080, height=1920, fps=59.0], colorTransformId 1, defaultColorTransformId 1, supportedColorTransforms [id=1, colorTransform=0], rotation 0, density 480 (403.411 x 406.4) dpi, layerStack 0, appVsyncOff 0, presDeadline 17949152, type BUILT_IN, state OFF, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS,DisplayMetricsdensity=3.0, width=1080, height=1920, scaledDensity=3.0, xdpi=403.411, ydpi=406.4, isValid=true
 

2.3 查看包名和类名 

adb shell dumpsys window > window.log
 

2.3.1 查看当前层叠的窗口

关键字: WINDOW MANAGER ANIMATOR STATE
WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)
DisplayContentsAnimator #0:
Window #0: WindowStateAnimatorc3aeae1 com.android.systemui.ImageWallpaper
Window #1: WindowStateAnimator3acc006 com.android.launcher3/com.android.launcher3.Launcher
Window #2: WindowStateAnimator9d36a5e com.android.settings/com.android.settings.Settings
Window #3: WindowStateAnimator10674f4 KeyguardScrim
Window #4: WindowStateAnimator1a541d StatusBar
Window #5: WindowStateAnimatorc44d692 Heads Up
 

2.3.2 查看发生ANR的类

关键字:WINDOW MANAGER LAST ANR
WINDOW MANAGER LAST ANR (dumpsys window lastanr)
ANR time: 9/14/16 3:30 PM
Application at fault: AppWindowToken192be11 token=Tokenfa10308 ActivityRecord58e30ab u0 com.android.touchtest/.MainActivity t14
Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.

 

2.4 查看最近任务列表

adb shell dumpsys activity > activity.log
adb shell dumpsys dumpsys activity recents
 

2.4.1 关键字:ACTIVITY MANAGER RECENT TASKS

ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)
Recent tasks:
* Recent #0: TaskRecorde61b9b8 #15 A=android.contacts.peopleActivity U=0 sz=1
* Recent #1: TaskRecord2825391 #1 A=com.android.launcher3 U=0 sz=1
* Recent #2: TaskRecorda19f2f6 #9 I=com.android.vending/com.google.android.vending.verifier.ConsentDialog U=0 sz=0
* Recent #3: TaskRecord55796f7 #8 I=com.caf.fmradio/.FMRadio U=0 sz=0
* Recent #4: TaskRecord54b964 #7 A=com.android.settings U=0 sz=0
更详细信息:
关键字:ACTIVITY MANAGER ACTIVITIES
 

2.4.2 crashed应用

关键字:Time since processes crashed
Time since processes crashed:
Process com.google.android.setupwizard uid 10025: last crashed +1h12m50s573ms ago
Process com.android.touchtest uid 10090: last crashed +52m25s195ms ago

博客原文:http://blog.csdn.net/yelangjueqi/article/details/52575233
 

三 adb shell am 常用命令

zhanghu@winth:~$ adb shell am
usage: am [subcommand] [options]
usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
[--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]
[--user <USER_ID> | current] <INTENT>
am startservice [--user <USER_ID> | current] <INTENT>
am stopservice [--user <USER_ID> | current] <INTENT>
am force-stop [--user <USER_ID> | all | current] <PACKAGE>
am kill [--user <USER_ID> | all | current] <PACKAGE>
am kill-all
am broadcast [--user <USER_ID> | all | current] <INTENT>
am instrument [-r] [-e <NAME> <VALUE>] [-p <FILE>] [-w]
[--user <USER_ID> | current]
[--no-window-animation] [--abi <ABI>] <COMPONENT>
am profile start [--user <USER_ID> current] [--sampling INTERVAL] <PROCESS> <FILE>
am profile stop [--user <USER_ID> current] [<PROCESS>]
am dumpheap [--user <USER_ID> current] [-n] <PROCESS> <FILE>
am set-debug-app [-w] [--persistent] <PACKAGE>
am clear-debug-app
am set-watch-heap <PROCESS> <MEM-LIMIT>
am clear-watch-heap
am monitor [--gdb <port>]
am hang [--allow-restart]
am restart
am idle-maintenance
am screen-compat [on|off] <PACKAGE>
am package-importance <PACKAGE>
am to-uri [INTENT]
am to-intent-uri [INTENT]
am to-app-uri [INTENT]
am switch-user <USER_ID>
am start-user <USER_ID>
am stop-user [-w] <USER_ID>
am stack start <DISPLAY_ID> <INTENT>
am stack movetask <TASK_ID> <STACK_ID> [true|false]
am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>
am stack split <STACK_ID> <v|h> [INTENT]
am stack list
am stack info <STACK_ID>
am task lock <TASK_ID>
am task lock stop
am task resizeable <TASK_ID> [true|false]
am task resize <TASK_ID> <LEFT,TOP,RIGHT,BOTTOM>
am get-config
am set-inactive [--user <USER_ID>] <PACKAGE> true|false
am get-inactive [--user <USER_ID>] <PACKAGE>
am send-trim-memory [--user <USER_ID>] <PROCESS>
[HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]

am start: start an Activity. Options are:
-D: enable debugging
-W: wait for launch to complete
--start-profiler <FILE>: start profiler and send results to <FILE>
--sampling INTERVAL: use sample profiling with INTERVAL microseconds
between samples (use with --start-profiler)
-P <FILE>: like above, but profiling stops when app goes idle
-R: repeat the activity launch <COUNT> times. Prior to each repeat,
the top activity will be finished.
-S: force stop the target app before starting the activity
--opengl-trace: enable tracing of OpenGL functions
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.

am startservice: start a Service. Options are:
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.

am stopservice: stop a Service. Options are:
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.

am force-stop: force stop everything associated with <PACKAGE>.
--user <USER_ID> | all | current: Specify user to force stop;
all users if not specified.

am kill: Kill all processes associated with <PACKAGE>. Only kills.
processes that are safe to kill -- that is, will not impact the user
experience.
--user <USER_ID> | all | current: Specify user whose processes to kill;
all users if not specified.

am kill-all: Kill all background processes.

am broadcast: send a broadcast Intent. Options are:
--user <USER_ID> | all | current: Specify which user to send to; if not
specified then send to all users.
--receiver-permission <PERMISSION>: Require receiver to hold permission.

am instrument: start an Instrumentation. Typically this target <COMPONENT>
is the form <TEST_PACKAGE>/<RUNNER_CLASS>. Options are:
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with
[-e perf true] to generate raw output for performance measurements.
-e <NAME> <VALUE>: set argument <NAME> to <VALUE>. For test runners a
common form is [-e <testrunner_flag> <value>[,<value>...]].
-p <FILE>: write profiling data to <FILE>
-w: wait for instrumentation to finish before returning. Required for
test runners.
--user <USER_ID> | current: Specify user instrumentation runs in;
current user if not specified.
--no-window-animation: turn off window animations while running.
--abi <ABI>: Launch the instrumented process with the selected ABI.
This assumes that the process supports the selected ABI.

am profile: start and stop profiler on a process. The given <PROCESS> argument
may be either a process name or pid. Options are:
--user <USER_ID> | current: When supplying a process name,
specify user of process to profile; uses current user if not specified.

am dumpheap: dump the heap of a process. The given <PROCESS> argument may
be either a process name or pid. Options are:
-n: dump native heap instead of managed heap
--user <USER_ID> | current: When supplying a process name,
specify user of process to dump; uses current user if not specified.

am set-debug-app: set application <PACKAGE> to debug. Options are:
-w: wait for debugger when application starts
--persistent: retain this value

am clear-debug-app: clear the previously set-debug-app.

am set-watch-heap: start monitoring pss size of <PROCESS>, if it is at or
above <HEAP-LIMIT> then a heap dump is collected for the user to report

am clear-watch-heap: clear the previously set-watch-heap.

am bug-report: request bug report generation; will launch UI
when done to select where it should be delivered.

am monitor: start monitoring for crashes or ANRs.
--gdb: start gdbserv on the given port at crash/ANR

am hang: hang the system.
--allow-restart: allow watchdog to perform normal system restart

am restart: restart the user-space system.

am idle-maintenance: perform idle maintenance now.

am screen-compat: control screen compatibility mode of <PACKAGE>.

am package-importance: print current importance of <PACKAGE>.

am to-uri: print the given Intent specification as a URI.

am to-intent-uri: print the given Intent specification as an intent: URI.

am to-app-uri: print the given Intent specification as an android-app: URI.

am switch-user: switch to put USER_ID in the foreground, starting
execution of that user if it is currently stopped.

am start-user: start USER_ID in background if it is currently stopped,
use switch-user if you want to start the user in foreground.

am stop-user: stop execution of USER_ID, not allowing it to run any
code until a later explicit start or switch to it.
-w: wait for stop-user to complete.

am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.

am stack movetask: move <TASK_ID> from its current stack to the top (true) or bottom (false) of <STACK_ID>.

am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>.

am stack split: split <STACK_ID> into 2 stacks <v>ertically or <h>orizontally
starting the new stack with [INTENT] if specified. If [INTENT] isn't
specified and the current stack has more than one task, then the top task
of the current task will be moved to the new stack. Command will also force
all current tasks in both stacks to be resizeable.

am stack list: list all of the activity stacks and their sizes.

am stack info: display the information about activity stack <STACK_ID>.

am task lock: bring <TASK_ID> to the front and don't allow other tasks to run.

am task lock stop: end the current task lock.

am task resizeable: change if <TASK_ID> is resizeable (true) or not (false).

am task resize: makes sure <TASK_ID> is in a stack with the specified bounds.
Forces the task to be resizeable and creates a stack if no existing stack
has the specified bounds.

am get-config: retrieve the configuration and any recent configurations
of the device.

am set-inactive: sets the inactive state of an app.

am get-inactive: returns the inactive state of an app.

am send-trim-memory: Send a memory trim event to a <PROCESS>.

<INTENT> specifications include these flags and arguments:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
[--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE> ...]
[--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]
[--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
[--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as Integer[])
[--eial <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
(mutiple extras passed as List<Integer>)
[--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as Long[])
[--elal <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
(mutiple extras passed as List<Long>)
[--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as Float[])
[--efal <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]]
(mutiple extras passed as List<Float>)
[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as String[]; to embed a comma into a string,
escape it using "\\,")
[--esal <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(mutiple extras passed as List<String>; to embed a comma into a string,
escape it using "\\,")
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--selector]
[<URI> | <PACKAGE> | <COMPONENT>]
 

3.1 发送广播

adb shell am broadcast -a "action"
其他更多信息见上面的 <INTENT> 介绍。
 

3.2 停止一个应用

adb shell am force-stop com.android.settings
 

3.3 查看最近任务列表

adb shell am stack list
zhanghu@winth:~$ adb shell am stack list
Stack id=0 bounds=[0,0][1080,1920] displayId=0
taskId=13: com.android.systemui/com.android.systemui.recents.RecentsActivity
taskId=11: com.android.launcher3/com.android.launcher3.Launcher

Stack id=2 bounds=[0,0][1080,1920] displayId=0
taskId=14: com.android.settings/com.android.settings.Settings
taskId=16: com.android.mms/com.android.mms.ui.ConversationList
taskId=15: com.android.contacts/com.android.contacts.activities.PeopleActivity
taskId=17: com.android.camera3/com.android.camera.CameraLauncher
 

3.4 获取资源配置信息

adb shell am get-config
中文简体环境
zhanghu@winth:~$ adb shell am get-config
config: mcc460-mnc2-zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
abi: arm64-v8a,armeabi-v7a,armeabi
recentConfigs:
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h640dp-normal-long-notround-port-xxhdpi-notouch-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: mcc460-mnc2-zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-xxhdpi-notouch-keysexposed-nokeys-navhidden-nonav-v23
config: mcc460-mnc2-zh-rCN-ldltr-sw360dp-w640dp-h335dp-normal-long-notround-land-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w640dp-h335dp-normal-long-notround-land-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23


英文环境
zhanghu@winth:~$ adb shell am get-config
config: mcc460-mnc2-en-rUS-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
abi: arm64-v8a,armeabi-v7a,armeabi
recentConfigs:
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h640dp-normal-long-notround-port-xxhdpi-notouch-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: mcc460-mnc2-zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-xxhdpi-notouch-keysexposed-nokeys-navhidden-nonav-v23
config: mcc460-mnc2-zh-rCN-ldltr-sw360dp-w640dp-h335dp-normal-long-notround-land-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: zh-rCN-ldltr-sw360dp-w640dp-h335dp-normal-long-notround-land-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23
config: mcc460-mnc2-en-rUS-ldltr-sw360dp-w360dp-h615dp-normal-long-notround-port-notnight-xxhdpi-finger-keysexposed-nokeys-navhidden-nonav-v23

 

四 获取settings表和SystemProperties的数据

 

4.1 查看settings表的数据

zhanghu@winth:~$ adb shell settings --help
usage: settings [--user NUM] get namespace key
settings [--user NUM] put namespace key value
settings [--user NUM] delete namespace key
settings [--user NUM] list namespace

'namespace' is one of system, secure, global, case-insensitive
If '--user NUM' is not given, the operations are performed on the owner user.

eg:
zhanghu@winth:~$ adb shell settings list system
614826A2C08954C4136F2E9DDA00A2A4=92F08A6DD962C3F57995B677E553FA32
accelerometer_rotation=0
alarm_alert=content://media/internal/audio/media/7
apn=CMWAP
bd_setting_i=861263030040457
camera_state_changed=false
cellular_to_wlan_type=0
cmcc_wifi_default_value=1
.,,,,,
 

4.2 查看SystemProperties的数据

zhanghu@winth:~$ adb shell getprop --help
usage: getprop [NAME [DEFAULT]]

Gets an Android system property, or lists them all.

zhanghu@winth:~$ adb shell getprop
[DEVICE_PROVISIONED]: [1]
[af.fast_track_multiplier]: [1]
[audio.deep_buffer.media]: [true]
[audio.dolby.ds2.enabled]: [true]
[audio.offload.buffer.size.kb]: [64]
......

 

五 控制多媒体播放

zhanghu@winth:~$ adb shell media
usage: media [subcommand] [options]
media dispatch KEY
media list-sessions
media monitor <tag>

media dispatch: dispatch a media key to the system.
KEY may be: play, pause, play-pause, mute, headsethook,
stop, next, previous, rewind, record, fast-forword.
media list-sessions: print a list of the current sessions.
media monitor: monitor updates to the specified session.
Use the tag from list-sessions.


zhanghu@winth:~$ adb shell media dispatch play

frameworks/base/cmds/media/src/com/android/commands/media/Media.java

   private void runDispatch() throws Exception 
        String cmd = nextArgRequired();
        int keycode;
        if ("play".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_PLAY;
         else if ("pause".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_PAUSE;
         else if ("play-pause".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
         else if ("mute".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MUTE;
         else if ("headsethook".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_HEADSETHOOK;
         else if ("stop".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_STOP;
         else if ("next".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_NEXT;
         else if ("previous".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
         else if ("rewind".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_REWIND;
         else if ("record".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_RECORD;
         else if ("fast-forward".equals(cmd)) 
            keycode = KeyEvent.KEYCODE_MEDIA_FAST_FORWARD;
         else 
            showError("Error: unknown dispatch code '" + cmd + "'");
            return;
        

        final long now = SystemClock.uptimeMillis();
        sendMediaKey(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keycode, 0, 0,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
        sendMediaKey(new KeyEvent(now, now, KeyEvent.ACTION_UP, keycode, 0, 0,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, InputDevice.SOURCE_KEYBOARD));
    



 

六 模拟输入按键

zhanghu@winth:~$ adb shell input
Usage: input [<source>] <command> [<arg>...]

The sources are: 
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad

The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)

eg:
模拟输入power按键
zhanghu@winth:~$ adb shell input keyevent KEYCODE_POWER

zhanghu@winth:~$ adb shell input keyevent 26
 

七 查看输入法

zhanghu@winth:~$ adb shell ime 
usage: ime list [-a] [-s]
ime enable ID
ime disable ID
ime set ID

The list command prints all enabled input methods. Use
the -a option to see all input methods. Use
the -s option to see only a single summary line of each.

The enable command allows the given input method ID to be used.

The disable command disallows the given input method ID from use.

The set command switches to the given input method ID.
zhanghu@winth:~$ adb shell ime list -s
com.iflytek.inputmethod/.FlyIME
com.android.inputmethod.latin/.LatinIME
zhanghu@winth:~$ adb shell ime list -a
com.iflytek.inputmethod/.FlyIME:
mId=com.iflytek.inputmethod/.FlyIME mSettingsActivityName=com.iflytek.inputmethod.setting.container.LauncherSettingActivity
mIsDefaultResId=0x0
Service:
priority=100 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=com.iflytek.inputmethod.FlyIME
packageName=com.iflytek.inputmethod
enabled=true exported=false processName=com.iflytek.inputmethod
permission=android.permission.BIND_INPUT_METHOD
flags=0x0
com.android.inputmethod.latin/.LatinIME:
mId=com.android.inputmethod.latin/.LatinIME mSettingsActivityName=com.android.inputmethod.latin.settings.SettingsActivity
mIsDefaultResId=0x7f070000
Service:
priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=false
ServiceInfo:
name=com.android.inputmethod.latin.LatinIME
packageName=com.android.inputmethod.latin
labelRes=0x7f0a0038 nonLocalizedLabel=null icon=0x0 banner=0x0
enabled=true exported=true processName=com.android.inputmethod.latin
permission=android.permission.BIND_INPUT_METHOD
flags=0x0
 

八 查看设备的分辨率

zhanghu@winth:~$ adb shell wm
usage: wm [subcommand] [options]
wm size [reset|WxH|WdpxHdp]
wm density [reset|DENSITY]
wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM]
wm scaling [off|auto]
wm screen-capture [userId] [true|false]

wm size: return or override display size.
width and height in pixels unless suffixed with 'dp'.

wm density: override display density.

wm overscan: set overscan area for display.

wm scaling: set display scaling mode.

wm screen-capture: enable/disable screen capture.

wm dismiss-keyguard: dismiss the keyguard, prompting the user for auth if necessary.

zhanghu@winth:~$ adb shell wm size
Physical size: 1080x1920
zhanghu@winth:~$ adb shell wm density
Physical density: 480
zhanghu@winth:~$ 


九 ContentProvider增删改查

zhanghu@winth:~$ adb shell content
usage: adb shell content [subcommand] [options]

usage: adb shell content insert --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...]
<URI> a content provider URI.
<BINDING> binds a typed value to a column and is formatted:
<COLUMN_NAME>:<TYPE>:<COLUMN_VALUE> where:
<TYPE> specifies data type such as:
b - boolean, s - string, i - integer, l - long, f - float, d - double
Note: Omit the value for passing an empty string, e.g column:s:
Example:
# Add "new_setting" secure setting with value "new_value".
adb shell content insert --uri content://settings/secure --bind name:s:new_setting --bind value:s:new_value

usage: adb shell content update --uri <URI> [--user <USER_ID>] [--where <WHERE>]
<WHERE> is a SQL style where clause in quotes (You have to escape single quotes - see example below).
Example:
# Change "new_setting" secure setting to "newer_value".
adb shell content update --uri content://settings/secure --bind value:s:newer_value --where "name='new_setting'"

usage: adb shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING> [--bind <BINDING>...] [--where <WHERE>]
Example:
# Remove "new_setting" secure setting.
adb shell content delete --uri content://settings/secure --where "name='new_setting'"

usage: adb shell content query --uri <URI> [--user <USER_ID>] [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>]
<PROJECTION> is a list of colon separated column names and is formatted:
<COLUMN_NAME>[:<COLUMN_NAME>...]
<SORT_ORDER> is the order in which rows in the result should be sorted.
Example:
# Select "name" and "value" columns from secure settings where "name" is equal to "new_setting" and sort the result by name in ascending order.
adb shell content query --uri content://settings/secure --projection name:value --where "name='new_setting'" --sort "name ASC"

usage: adb shell content call --uri <URI> --method <METHOD> [--arg <ARG>]
[--extra <BINDING> ...]
<METHOD> is the name of a provider-defined method
<ARG> is an optional string argument
<BINDING> is like --bind above, typed data of the form <KEY>:b,s,i,l,f,d:<VAL>

usage: adb shell content read --uri <URI> [--user <USER_ID>]
Example:
# cat default ringtone to a file, then pull to host
adb shell 'content read --uri content://settings/system/ringtone > /mnt/sdcard/tmp.ogg' && adb pull /mnt/sdcard/tmp.ogg
 

十 查看拨号盘

zhanghu@winth:~$ adb shell telecom
usage: telecom [subcommand] [options]
usage: telecom set-phone-account-enabled <COMPONENT> <ID>
usage: telecom set-phone-account-disabled <COMPONENT> <ID>
usage: telecom register-phone-account <COMPONENT> <ID> <LABEL>
usage: telecom register-sim-phone-account <COMPONENT> <ID> <LABEL> <ADDRESS>
usage: telecom unregister-phone-account <COMPONENT> <ID>
usage: telecom set-default-dialer <PACKAGE>
usage: telecom get-default-dialer
usage: telecom get-system-dialer

telecom set-phone-account-enabled: Enables the given phone account, if it has 
already been registered with Telecom.

telecom set-phone-account-disabled: Disables the given phone account, if it 
has already been registered with telecom.

telecom set-default-dialer: Sets the default dialer to the given component. 

telecom get-default-dialer: Displays the current default dialer. 

telecom get-system-dialer: Displays the current system dialer. 

zhanghu@winth:~$ adb shell telecom get-system-dialer
com.android.contacts
zhanghu@winth:~$ adb shell telecom get-default-dialer
com.android.contacts
zhanghu@winth:~$ adb shell telecom set-default-dialer com.test.test //设置包名为com.test.test 的应用为默认拨号
Error - com.test.test is not an installed Dialer app, 
or is already the default dialer.
 

十一 控制关机,重启,数据连接打开,wifi是否打开,usb的状态

zhanghu@winth:~$ adb shell svc --help
Available commands:
help Show information about the subcommands
power Control the power manager
data Control mobile data connectivity
wifi Control the Wi-Fi manager
usb Control Usb state

zhanghu@winth:~$ adb shell svc power
Control the power manager
usage: svc power stayon [true|false|usb|ac|wireless] 
Set the 'keep awake while plugged in' setting.
svc power reboot [reason] //重启机器
Perform a runtime shutdown and reboot device with specified reason.
svc power shutdown //关机

Perform a runtime shutdown and power off the device.

 

$adb shell svc power shutdown     // 关机

 

十二 截屏

zhanghu@winth:~$ adb shell screencap /sdcard/screen.png && adb pull /sdcard/screen.png ~/logloglogloglogloglog/
 

十三 dump当前布局

zhanghu@winth:~$ adb shell uiautomator dump && adb pull /sdcard/window_dump.xml ~/logloglogloglogloglog/
 

十四 在设备内创建文件夹

adb shell mkdir /sdcard/LOG
 

十五 adb logcat 命令

A 同时过滤多个应用的Tag

语法:
adb logcat *:S TAG1 TAG2 TAG3

adb logcat -s TAG1 TAG2 TAG3
eg: 
zhanghu@winth:~$ adb logcat *:S CAM_Activity KeyEventDispatcher 
zhanghu@winth:~$ adb logcat -s CAM_Activity KeyEventDispatcher
 

B 过滤单个应用的Tag

语法:
adb logcat *:S TAG 或 adb logcat -s TAG
 

C 过滤应用指定级别的Tag

语法:
adb logcat -s <tag>[:priority] <tag2>[:priority]
where <tag> is a log component tag (or * for all) and priority is:
V Verbose (default for <tag>)
D Debug (default for '*')
I Info
W Warn
E Error
F Fatal
S Silent (suppress all output)

eg:
zhanghu@winth:~$ adb logcat -s WindowManager:E
zhanghu@winth:~$ adb logcat -s WindowManager:E KeyguardUpdateMonitor:D
zhanghu@winth:~$ adb logcat -s *:E
 

D 过滤含有多个字符串的行

语法:
adb logcat |grep -E “string1|string2” 或 adb logcat |grep -E ’string1|string2‘
eg:
zhanghu@winth:~$ adb logcat |grep -E 'Window|Keyguard'
 

补充几条grep命令:

1)  搜索命令:grep -nrw  “abcd” . 在当前文件夹下搜索abcd。

2)  如果在只是想匹配模式的上下几行,grep可以实现。

$grep -5 'parttern' inputfile //打印匹配行的前后5行

$grep -C 5 'parttern' inputfile //打印匹配行的前后5行

$grep -A 5 'parttern' inputfile //打印匹配行的后5行

$grep -B 5 'parttern' inputfile //打印匹配行的前5行

--------------------- 作者:ShyBoy天天向上 来源:CSDN 原文:https://blog.csdn.net/yelangjueqi/article/details/52575233?utm_source=copy 版权声明:本文为博主原创文章,转载请附上博文链接!

以上是关于Android adb shell后面可用的常用命令详细列举的主要内容,如果未能解决你的问题,请参考以下文章

adb shell 入门

Android下adb shell的使用

adb shell 发送广播

Android 通过adb shell am broadcast发送广播

如何在android程序中执行adb shell命令

如何在android程序中执行adb shell命令