项目中adb shell am 常见用法
am start
C:\Users>adb shell am start
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]
启动activity
usage: am start [-D] [-W] [-P <FILE>] [--start-profiler <FILE>]
[--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]
[--user <USER_ID> | current] <INTENT>
am start: start an Activity. Options are:
//开启debug模式
-D: enable debugging
//等待启动完成
-W: wait for launch to complete
//将profiler中的结果输出到指定文件中
--start-profiler <FILE>: start profiler and send results to <FILE>
//采样,需和start-profiler一起使用
--sampling INTERVAL: use sample profiling with INTERVAL microseconds
between samples (use with --start-profiler)
//和--start-profiler一样,区别在于,在app进入idle状态时profiler结束
-P <FILE>: like above, but profiling stops when app goes idle
//重复启动Activity,但每次重复启动都会关闭掉最上面的Activity
-R: repeat the activity launch <COUNT> times. Prior to each repeat,
the top activity will be finished.
//关闭Activity所属的App进程后再启动Activity
-S: force stop the target app before starting the activity
//开启OpenGL tracing
--opengl-trace: enable tracing of OpenGL functions
//使用指定的用户来启动activity,如果不输入,则使用当前用户执行
--user <USER_ID> | current: Specify which user to run as; if not
specified then run as the current user.
示例:
- -n 使用组件名方式启动照相机功能
C:\Users>adb shell am start -n com.android.camera/.Camera
Starting: Intent { cmp=com.android.camera/.Camera }
- -p 先停止目标应用,再启动
C:\Users>adb shell am start -S com.android.camera/.Camera
Stopping: com.android.camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
- -w 等待应用完成启动
C:\Users>adb shell am start -W com.android.camera/.Camera
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.camera/.Camera }
Status: ok
Activity: com.android.camera/.Camera
ThisTime: 295
TotalTime: 295
WaitTime: 314
Complete
- -a Intent加参数
//打开拨号界面,并传递一个DATA_URI数据给拨号界面
am start -a android.intent.action.CALL -d tel:10086
//加Extra, 键值对
adb shell am start -a com.example.bianji.changedata -e lon 31.23037123456 -e lan 121.4737123456
//给特定号码发送短信
C:\Users>adb shell am start -a android.intent.action.SENDTO -d sms:10086 --es sms_body cxye
Starting: Intent { act=android.intent.action.SENDTO dat=sms:xxxxx (has extras) }
- 反编译调试
//微信
adb shell am start -D -W -n com.tencent.mm/com.tencent.mm.ui.LauncherUI
//微博
adb shell am start -D -W -n com.sina.weibo/com.sina.weibo.SplashActivity
其他参数 如 CATEGORY、MIME_TYPE再探讨。
service 与 broadcast
启动service与broadcast用法与activity类似
//toolAPP中两种方法拷贝文字:
am broadcast -a com.example.copy.text -e "content" "12345678"
am startservice -a com.example.copy.text.second -e "content" "12345678"
INTENT参数:
<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>]