使用Android adb命令来启动Android应用程序


Android自带的ADB工具是一个很强大的工具,我们可以用ADB来完成非常多的工作。

具体ADB的使用可以参考这篇文章:Android adb常用指令使用指南


如何安装一个android app程序,可以使用adb install ApkName.apk命令来实现,那么安装完成之后可不可以用命令行来启动它呢?

Of Course!!!

那么如何启动已经安装好的Android App程序吗?


我们可以在命令行输入一下内容:

[plain] view plain copy
  1. C:\Users\Administrator>adbshellamstart-aandroid.intent.action.MAIN-candroid.intent.category.LAUNCHER-nnet.micod
  2. e.fileexplorer/net.micode.fileexplorer.FileExplorerTabActivity
  3. Starting:Intent{act=android.intent.action.MAINcat=[android.intent.category.LAUNCHER]cmp=net.micode.fileexplorer/.Fi
  4. leExplorerTabActivity}


有同学要说,上面的命令太长了,不好记,老师,能不能给力点?

好的,我们可以精简下:

[plain] view plain copy
  1. C:\Users\Administrator>adbshellamstart-nnet.micode.fileexplorer/net.micode.fileexplorer.FileExplorerTabActivity
  2. Starting:Intent{cmp=net.micode.fileexplorer/.FileExplorerTabActivity}
  3. C:\Users\Administrator>


其中FileExplorerTabActivity是fileexplorerApp应用程序的类名。


我们来看下adb shell am命令的帮助。

[plain] view plain copy
  1. C:\Users\Administrator>adbshellam
  2. usage:am[subcommand][options]
  3. usage:amstart[-D][-W][-P<FILE>][--start-profiler<FILE>]
  4. [--RCOUNT][-S]<INTENT>
  5. amstartservice<INTENT>
  6. amforce-stop<PACKAGE>
  7. amkill<PACKAGE>
  8. amkill-all
  9. ambroadcast<INTENT>
  10. aminstrument[-r][-e<NAME><VALUE>][-p<FILE>][-w]
  11. [--no-window-animation]<COMPONENT>
  12. amprofile[looper]start<PROCESS><FILE>
  13. amprofile[looper]stop[<PROCESS>]
  14. amdumpheap[flags]<PROCESS><FILE>
  15. amset-debug-app[-w][--persistent]<PACKAGE>
  16. amclear-debug-app
  17. ammonitor[--gdb<port>]
  18. amscreen-compat[on|off]<PACKAGE>
  19. amdisplay-size[reset|MxN]
  20. amto-uri[INTENT]
  21. amto-intent-uri[INTENT]
  22. amstart:startanActivity.Optionsare:
  23. -D:enabledebugging
  24. -W:waitforlaunchtocomplete
  25. --start-profiler<FILE>:startprofilerandsendresultsto<FILE>
  26. -P<FILE>:likeabove,butprofilingstopswhenappgoesidle
  27. -R:repeattheactivitylaunch<COUNT>times.Priortoeachrepeat,
  28. thetopactivitywillbefinished.
  29. -S:forcestopthetargetappbeforestartingtheactivity
  30. amstartservice:startaService.
  31. amforce-stop:forcestopeverythingassociatedwith<PACKAGE>.
  32. amkill:Killallprocessesassociatedwith<PACKAGE>.Onlykills.
  33. processesthataresafetokill--thatis,willnotimpacttheuser
  34. experience.
  35. amkill-all:Killallbackgroundprocesses.
  36. ambroadcast:sendabroadcastIntent.
  37. aminstrument:startanInstrumentation.Typicallythistarget<COMPONENT>
  38. istheform<TEST_PACKAGE>/<RUNNER_CLASS>.Optionsare:
  39. -r:printrawresults(otherwisedecodeREPORT_KEY_STREAMRESULT).Usewith
  40. [-eperftrue]togeneraterawoutputforperformancemeasurements.
  41. -e<NAME><VALUE>:setargument<NAME>to<VALUE>.Fortestrunnersa
  42. commonformis[-e<testrunner_flag><value>[,<value>...]].
  43. -p<FILE>:writeprofilingdatato<FILE>
  44. -w:waitforinstrumentationtofinishbeforereturning.Requiredfor
  45. testrunners.
  46. --no-window-animation:turnoffwindowanimationswillrunning.
  47. amprofile:startandstopprofileronaprocess.
  48. amdumpheap:dumptheheapofaprocess.Optionsare:
  49. -n:dumpnativeheapinsteadofmanagedheap
  50. amset-debug-app:setapplication<PACKAGE>todebug.Optionsare:
  51. -w:waitfordebuggerwhenapplicationstarts
  52. --persistent:retainthisvalue
  53. amclear-debug-app:clearthepreviouslyset-debug-app.
  54. ammonitor:startmonitoringforcrashesorANRs.
  55. --gdb:startgdbservonthegivenportatcrash/ANR
  56. amscreen-compat:controlscreencompatibilitymodeof<PACKAGE>.
  57. amdisplay-size:overridedisplaysize.
  58. amto-uri:printthegivenIntentspecificationasaURI.
  59. amto-intent-uri:printthegivenIntentspecificationasanintent:URI.
  60. <INTENT>specificationsincludetheseflagsandarguments:
  61. [-a<ACTION>][-d<DATA_URI>][-t<MIME_TYPE>]
  62. [-c<CATEGORY>[-c<CATEGORY>]...]
  63. [-e|--es<EXTRA_KEY><EXTRA_STRING_VALUE>...]
  64. [--esn<EXTRA_KEY>...]
  65. [--ez<EXTRA_KEY><EXTRA_BOOLEAN_VALUE>...]
  66. [--ei<EXTRA_KEY><EXTRA_INT_VALUE>...]
  67. [--el<EXTRA_KEY><EXTRA_LONG_VALUE>...]
  68. [--eu<EXTRA_KEY><EXTRA_URI_VALUE>...]
  69. [--eia<EXTRA_KEY><EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]
  70. [--ela<EXTRA_KEY><EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]
  71. [-n<COMPONENT>][-f<FLAGS>]
  72. [--grant-read-uri-permission][--grant-write-uri-permission]
  73. [--debug-log-resolution][--exclude-stopped-packages]
  74. [--include-stopped-packages]
  75. [--activity-brought-to-front][--activity-clear-top]
  76. [--activity-clear-when-task-reset][--activity-exclude-from-recents]
  77. [--activity-launched-from-history][--activity-multiple-task]
  78. [--activity-no-animation][--activity-no-history]
  79. [--activity-no-user-action][--activity-previous-is-top]
  80. [--activity-reorder-to-front][--activity-reset-task-if-needed]
  81. [--activity-single-top][--activity-clear-task]
  82. [--activity-task-on-home]
  83. [--receiver-registered-only][--receiver-replace-pending]
  84. [--selector]
  85. [<URI>|<PACKAGE>|<COMPONENT>]


来源:http://blog.csdn.net/tcpipstack/article/details/8553965

更多相关文章

  1. Android的一些常用命令提示符(cmd)指令
  2. Android(安卓)Launcher 分析
  3. Android应用程序窗口(Activity)的运行上下文环境(Context)的创建过程
  4. 命令行下Android应用开发
  5. Android编译详解之lunch命令
  6. Android上的单元测试
  7. Android启动页上下白屏适配
  8. Android(安卓)快速运行的秘诀
  9. 理解Android(安卓)上的安全性

随机推荐

  1. 【Android】编写一个简易计算机
  2. android之seekBar
  3. android 入门 AlarmManager 例子
  4. Android路径大全
  5. android sqlite 一次创建多个表
  6. Unable to execute dex: java.nio.Buffer
  7. android 状态栏显示运行图标
  8. Android(安卓)之ContextMenu上下文菜单
  9. HTML5 Cache, Android(安卓)WebView
  10. Android(安卓)动态获取资源ID