命令行执行Android程序

一直以来都是用adb install xxx.apk来安装Android的package,然后在模拟器的menu screen上点击执行程序,今天需要在命令行中执行Android程序,查了半天,终于找到了相应的指令:

首先我们看看am指令介绍吧:

  1. # am 
  2. usage: am [subcommand] [options] 
  3.  
  4.     start an Activity: am start [-D] [-W]  
  5.         -D: enable debugging 
  6.         -W: wait for launch to complete 
  7.  
  8.     start a Service: am startservice  
  9.  
  10.     send a broadcast Intent: am broadcast  
  11.  
  12.     start an Instrumentation: am instrument [flags]  
  13.         -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT) 
  14.         -e <NAMEset argument <NAMEto  
  15.         -p : write profiling data to  
  16.         -w: wait for instrumentation to finish before returning 
  17.  
  18.     start profiling: am profile  start  
  19.     stop profiling: am profile  stop 
  20.  
  21.      specifications include these flags: 
  22.         [-a <ACTION>] [-d ] [-t 
  23.         [-c  [-c ] …] 
  24.         [-e|–es   …] 
  25.         [–esn  …] 
  26.         [–ez   …] 
  27.         [-e|–ei   …] 
  28.         [-n ] [-f 
  29.         [–grant-read-uri-permission] [–grant-write-uri-permission] 
  30.         [–debug-log-resolution] 
  31.         [–activity-brought-to-front] [–activity-clear-top] 
  32.         [–activity-clear-when-task-reset] [–activity-exclude-from-recents] 
  33.         [–activity-launched-from-history] [–activity-multiple-task] 
  34.         [–activity-no-animation] [–activity-no-history] 
  35.         [–activity-no-user-action] [–activity-previous-is-top] 
  36.         [–activity-reorder-to-front] [–activity-reset-task-if-needed] 
  37.         [–activity-single-top] 
  38.         [–receiver-registered-only] [–receiver-replace-pending] 
  39.         [

从上可知:

am start 用来启动一个activity

am startservice 用来启动一个service,比如我们要

am broadcast 用来发送一个广播

当我们要运行camera程序时,可以用以下命令:

# am start -n com.android.camera/com.android.camera.Camera

或者打开Linux公社(LinuxIDC.com