命令行执行Android程序

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)

本文转自:命令行执行Android程序_Mobile and Linux Development的技术博客_51CTO博客

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

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

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

从上可知:

am start 用来启动一个activity

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

am broadcast 用来发送一个广播

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

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

或者打开百度的网站,可以用以下命令

# am start -a android.intent.action.VIEW -d http://www.baidu.com
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值