am

来自个人维基
跳转至: 导航搜索

Android的一个命令,用来启动应用程序,它采用的是和应用程序完全一样的发送intent的方式来启用

是ActivityManager的缩写。

am命令帮助

# am
usage: am [subcommand] [options]

   start an Activity: am start [-D] [-W] <INTENT>
       -D: enable debugging
       -W: wait for launch to complete

   start a Service: am startservice <INTENT>

   send a broadcast Intent: am broadcast <INTENT>

   start an Instrumentation: am instrument [flags] <COMPONENT>
       -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
       -e <NAME> <VALUE>: set argument <NAME> to <VALUE>
       -p <FILE>: write profiling data to <FILE>
       -w: wait for instrumentation to finish before returning

   start profiling: am profile <PROCESS> start <FILE>
   stop profiling: am profile <PROCESS> stop

   <INTENT> specifications include these flags:
       [-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> ...]
       [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
       [-n <COMPONENT>] [-f <FLAGS>]
       [--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]
       [<URI>]


使用举例:

am start -n com.google.android.browser/com.google.android.browser.BrowserActivity
am start -a android.intent.action.VIEW -d http://www.google.com/
am start -a android.intent.action.CALL -d tel:123456789


设置

am start -n com.android.settings/com.android.settings.Settings


am实际上是对app_process的一个简单的脚本封装。整个am源码如下所示:

cat am
# Script to start "am" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/am.jar
exec app_process $base/bin com.android.commands.am.Am "$@"