adb shell am 的用法

adb shell am
使用此命令可以从cmd控制台启动 activity, services;发送 broadcast等等:
 
 1 C:\Users\Administrator>adb shell am
 2 usage: am [subcommand] [options]
 3 
 4     start an Activity: am start [-D] [-W] <INTENT>
 5         -D: enable debugging
 6         -W: wait for launch to complete
 7 
 8     start a Service: am startservice <INTENT>
 9 
10     send a broadcast Intent: am broadcast <INTENT>
11 
12     start an Instrumentation: am instrument [flags] <COMPONENT>
13         -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
14         -e <NAME> <VALUE>: set argument <NAME> to <VALUE>
15         -p <FILE>: write profiling data to <FILE>
16         -w: wait for instrumentation to finish before returning
17 
18     start profiling: am profile <PROCESS> start <FILE>
19     stop profiling: am profile <PROCESS> stop
20 
21     start monitoring: am monitor [--gdb <port>]
22         --gdb: start gdbserv on the given port at crash/ANR
23 
24     <INTENT> specifications include these flags:
25         [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
26         [-c <CATEGORY> [-c <CATEGORY>] ...]
27         [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
28         [--esn <EXTRA_KEY> ...]
29         [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
30         [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
31         [-n <COMPONENT>] [-f <FLAGS>]
32         [--grant-read-uri-permission] [--grant-write-uri-permission]
33         [--debug-log-resolution]
34         [--activity-brought-to-front] [--activity-clear-top]
35         [--activity-clear-when-task-reset] [--activity-exclude-from-recents]
36         [--activity-launched-from-history] [--activity-multiple-task]
37         [--activity-no-animation] [--activity-no-history]
38         [--activity-no-user-action] [--activity-previous-is-top]
39         [--activity-reorder-to-front] [--activity-reset-task-if-needed]
40         [--activity-single-top]
41         [--receiver-registered-only] [--receiver-replace-pending]
42         [<URI>]

 

使用实例:
如启动一个 Activity:
 
格式:
adb shell am start -n 包名/包名+类名(-n 类名,-a action,-d date,-m MIME-TYPE,-c category,-e 扩展数据,等)。

实例1:

C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
 
实例2:(带extra 的 intent)
C:\Users\Administrator>adb shell am start -n com.android.camera/.Camera -e abc hello
Starting: Intent { cmp=com.android.camera/.Camera (has extras) }
其中 extra 的 key 为 abc ,value 为字串 "hello"
 
还可以发送命令模拟手机低电环境:

实例:

adb shell am broadcast -a android.intent.action.BATTERY_CHANGED --ei "level" 3 --ei "scale" 100

adb shell am 的用法,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。