命令行执行Android程序
2015 年 4 月 9 日
一直以来都是用adb install xxx.apk来安装Android的package,然后在模拟器的menu screen上点击执行程序,今天需要在命令行中执行Android程序,查了半天,终于找到了相应的指令:
首先我们看看am指令介绍吧:
- # am
- usage: am [subcommand] [options]
- start an Activity: am start [-D] [-W]
- -D: enable debugging
- -W: wait for launch to complete
- start a Service: am startservice
- send a broadcast Intent: am broadcast
- start an Instrumentation: am instrument [flags]
- -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
- -e <NAME>
: set argument <NAME> to - -p
: write profiling data to - -w: wait for instrumentation to finish before returning
- start profiling: am profile
start - stop profiling: am profile
stop -
specifications include these flags: - [-a <ACTION>] [-d
] [-t ] - [-c
[-c ] …] - [-e|–es
…] - [–esn
…] - [–ez
…] - [-e|–ei
…] - [-n
] [-f ] - [–grant-read-uri-permission] [–grant-write-uri-permission]
- [–debug-log-resolution]
- [–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]
- [–receiver-registered-only] [–receiver-replace-pending]
- [
]
从上可知:
am start 用来启动一个activity
am startservice 用来启动一个service,比如我们要
am broadcast 用来发送一个广播
当我们要运行camera程序时,可以用以下命令:
# am start -n com.android.camera/com.android.camera.Camera
或者打开Linux公社(LinuxIDC.com