Am命令用法(转)

<div id="article_content" class="article_content tracking-ad" data-mod="popu_307" data-dsm="post">


<h2 id="section" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:30px"><a name="t0" target="_blank"></a>
一、概述<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#section" style=""></a></h2>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
作为一名开发者,相信对adb指令一定不会陌生。那么在手机连接adb后,可通过am命令做很多操作:</p>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
(1) 拨打电话10086</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">adb shell am start -a android.intent.action.CALL -d tel:10086
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
(2) 打开网站<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">www.gityuan.com</code></p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">adb shell am start -a android.intent.action.VIEW -d  http://gityuan.com
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
(3) 启动Activity: 启动包名为<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">com.yuanhh.app</code>,主Activity为<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">.MainActivity</code>,且extra数据以”website”为key,
 “yuanh.com”为value。通过java代码要完成该功能虽然不复杂,但至少需要一个android环境,而通过adb的方式,只需要在adb窗口,输入如下命令便可完成:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am start -n com.yuanhh.app/.MainActivity -es website gityuan.com
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
am命令还可以启动Service、Broadcast,杀进程,监控等功能,这些功能都非常便捷调试程序,接下来讲述关于am更多更详细的功能。</p>
<h2 id="am" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:30px"><a name="t1" target="_blank"></a>
二、Am命令<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#am" style=""></a></h2>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
命令格式:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am [subcommand] [options]
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
命令列表:</p>
<div class="table-responsive" style="min-height:0.01%; overflow-x:auto; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<table class="table " style="border-spacing:0px; border-collapse:collapse; width:706px; max-width:100%; margin-bottom:20px; background-color:transparent">
<thead style="">
<tr style="">
<th style="padding:8px; border-top-width:0px; border-bottom-width:2px; border-bottom-style:solid; border-bottom-color:rgb(221,221,221); line-height:1.42857; vertical-align:bottom; border-right-width:1px!important; border-left-width:1px!important; border-right-style:solid!important; border-left-style:solid!important; border-right-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important">
命令</th>
<th style="padding:8px; border-top-width:0px; border-bottom-width:2px; border-bottom-style:solid; border-bottom-color:rgb(221,221,221); line-height:1.42857; vertical-align:bottom; border-right-width:1px!important; border-left-width:1px!important; border-right-style:solid!important; border-left-style:solid!important; border-right-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important">
功能</th>
<th style="padding:8px; border-top-width:0px; border-bottom-width:2px; border-bottom-style:solid; border-bottom-color:rgb(221,221,221); line-height:1.42857; vertical-align:bottom; border-right-width:1px!important; border-left-width:1px!important; border-right-style:solid!important; border-left-style:solid!important; border-right-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important">
实现方法</th>
</tr>
</thead>
<tbody style="">
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am start <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">[options</code>] <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><INTENT</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
启动Activity</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
startActivityAsUser</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am startservice <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><INTENT</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
启动Service</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
startService</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am stopservice <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><INTENT</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
停止Service</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
stopService</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am broadcast <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><INTENT</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
发送广播</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
broadcastIntent</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am kill <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><PACKAGE</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
杀指定后台进程</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
killBackgroundProcesses</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am kill-all</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
杀所有后台进程</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
killAllBackgroundProcesses</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am force-stop <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><PACKAGE</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
强杀进程</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
forceStopPackage</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am hang</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
系统卡住</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
hang</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am restart</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
重启</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
restart</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am bug-report</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
创建bugreport</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
requestBugReport</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am dumpheap <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><pid</code>> <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><file</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
进程pid的堆信息输出到file</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
dumpheap</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am send-trim-memory <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><pid</code>><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><level</code>></td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
收紧进程的内存</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
setProcessMemoryTrimLevel</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
am monitor</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
监控</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
MyActivityController.run</td>
</tr>
</tbody>
</table>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
am命令实的实现方式在Am.java,最终几乎都是调用<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">ActivityManagerService</code>相应的方法来完成的,<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">am
 monitor</code>除外。比如前面概述中介绍的命令<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">am start -a android.intent.action.VIEW
 -d http://gityuan.com</code>, 启动Acitivty最终调用的是ActivityManagerService类的startActivityAsUser()方法来完成的。再比如<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">am
 kill-all</code>命令,最终的实现工作是由ActivityManagerService的killBackgroundProcesses()方法完成的。</p>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
接下来,说说<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">[options</code>]和 <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><INTENT</code>>参数的意义以及如何正确取值。</p>
<h2 id="options" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:30px"><a name="t2" target="_blank"></a>
三、 Options<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#options" style=""></a></h2>
<h3 id="activity" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t3" target="_blank"></a>
3.1 启动Activity<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#activity" style=""></a></h3>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
主要是启动Activity命令<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">am start [options] <INTENT></code>使用options参数,接下来列举Activity命令的[options]参数:</p>
<ul style="margin-top:0px; margin-bottom:40px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<li style="">-D: 允许调试功能</li><li style="">-W: 等待app启动完成</li><li style="">-R <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><COUNT</code>>: 重复启动Activity COUNT次</li><li style="">-S: 启动activity之前,先调用forceStopPackage()方法强制停止app.</li><li style="">–opengl-trace: 运行获取OpenGL函数的trace</li><li style="">–user <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><USER_ID</code>> <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">|</code> current:
 指定用户来运行App,默认为当前用户。</li><li style="">–start-profiler <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><FILE</code>>: 启动profiler,并将结果发送到 <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><FILE</code>>;</li><li style="">-P <code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)"><FILE</code>>: 类似 –start-profiler,不同的是当app进入idle状态,则停止profiling</li><li style="">–sampling INTERVAL: 设置profiler 取样时间间隔,单位ms;</li></ul>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
启动Activity的实现原理: 存在-W参数则调用startActivityAndWait()方法来运行,否则startActivityAsUser()。</p>
<h3 id="section-1" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t4" target="_blank"></a>
3.2 收紧内存<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#section-1" style=""></a></h3>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
命令</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am send-trim-memory  <pid> <level>
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
例如: 向pid=12345的进程,发出level=RUNNING_LOW的收紧内存命令</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am send-trim-memory 12345 RUNNING_LOW。
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
那么level取值范围为: HIDDEN、RUNNING_MODERATE、BACKGROUND、RUNNING_LOW、MODERATE、RUNNING_CRITICAL、COMPLETE。</p>
<h3 id="section-2" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t5" target="_blank"></a>
3.3 其他<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#section-2" style=""></a></h3>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
对于am的子命令,startservice, stopservice, broadcast, kill, profile start, profile stop, dumpheap的可选参数都允许设置<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">--user
 <USER_ID></code>。目前市面上的绝大多数手机还是单用户模式,故可以忽略该参数,默认为当前用户。</p>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
例如:启动id=10010的用户的指定service。</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am startservice --user 10010
</code></pre>
</div>
<h2 id="intent" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:30px"><a name="t6" target="_blank"></a>
四、 Intent<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#intent" style=""></a></h2>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
Intent的参数和flags较多,本文为方便起见,分为3种类型参数,常用参数,Extra参数,Flags参数。</p>
<h3 id="section-3" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t7" target="_blank"></a>
4.1 常用参数<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#section-3" style=""></a></h3>
<ul style="margin-top:0px; margin-bottom:40px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-a <ACTION></code>: 指定Intent action, 实现原理Intent.setAction();</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-n <COMPONENT></code>: 指定组件名,格式为{包名}/.{主Activity名},实现原理Intent.setComponent();</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-d <DATA_URI></code>: 指定Intent data URI</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-t <MIME_TYPE></code>: 指定Intent MIME Type</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-c <CATEGORY> [-c <CATEGORY>] ...]</code>:指定Intent category,实现原理Intent.addCategory()</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-p <PACKAGE></code>: 指定包名,实现原理Intent.setPackage();</li><li style=""><code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-f <FLAGS></code>: 添加flags,实现原理Intent.setFlags(int ),紧接着的参数必须是int型;</li></ul>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
实例</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am start -a android.intent.action.VIEW
am start -n com.yuanhh.app/.MainActivity
am start -d content://contacts/people/1
am start -t image/png
am start -c android.intent.category.APP_CONTACTS
</code></pre>
</div>
<h3 id="extra" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t8" target="_blank"></a>
4.2 Extra参数<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#extra" style=""></a></h3>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<span style="font-weight:700">(1). 基本类型</span></p>
<div class="table-responsive" style="min-height:0.01%; overflow-x:auto; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<table class="table " style="border-spacing:0px; border-collapse:collapse; width:706px; max-width:100%; margin-bottom:20px; background-color:transparent">
<tbody style="">
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
参数</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-e/-es</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-esn</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-ez</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-ei</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-el</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-ef</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-eu</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-ecn</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
类型</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
String</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
(String)null</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
boolean</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
int</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
long</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
float</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
uri</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
component</td>
</tr>
</tbody>
</table>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
比如参数es是Extra String首字母简称,实例:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am start -n com.yuanhh.app/.MainActivity -es website gityuan.com 
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
此处<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-es website gityuan.com</code>,等价于Intent.putExtra(“website”, “gityuan.com”);</p>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<span style="font-weight:700">(2). 数组类型</span></p>
<div class="table-responsive" style="min-height:0.01%; overflow-x:auto; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<table class="table " style="border-spacing:0px; border-collapse:collapse; width:706px; max-width:100%; margin-bottom:20px; background-color:transparent">
<tbody style="">
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
参数</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-esa</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-eia</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-ela</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-efa</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
数组类型</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
String[]</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
int[]</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
long[]</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
float[]</td>
</tr>
</tbody>
</table>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
比如参数eia,是Extra int array首字母简称,多个value值之间以逗号隔开,实例:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am start -n com.yuanhh.app/.MainActivity -ela weekday 1,2,3,4,5 
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
此处<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-ela weekday 1,2,3,4,5</code>,等价于Intent.putExtra(“weekday”, new int[]{1,2,3,4,5});</p>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<span style="font-weight:700">(3). ArrayList类型</span></p>
<div class="table-responsive" style="min-height:0.01%; overflow-x:auto; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<table class="table " style="border-spacing:0px; border-collapse:collapse; width:706px; max-width:100%; margin-bottom:20px; background-color:transparent">
<tbody style="">
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
参数</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-esal</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-eial</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-elal</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
-efal</td>
</tr>
<tr style="">
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
List类型</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
String</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
int</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
long</td>
<td style="padding:8px; border-top-width:1px; border-right-width:1px!important; border-bottom-width:1px!important; border-left-width:1px!important; border-top-style:solid; border-right-style:solid!important; border-bottom-style:solid!important; border-left-style:solid!important; border-top-color:rgb(221,221,221); border-right-color:rgb(238,238,238)!important; border-bottom-color:rgb(238,238,238)!important; border-left-color:rgb(238,238,238)!important; line-height:1.42857; vertical-align:top">
float</td>
</tr>
</tbody>
</table>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
比如参数efal,是Extra float Array List首字母简称,多个value值之间以逗号隔开,实例:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am start -n com.yuanhh.app/.MainActivity -efal nums 1.2,2.2
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
此处<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-efal nums 1.2,2.2</code>,等价于先构造ArrayList变量,再通过putExtra放入第二个参数。</p>
<h3 id="flags" style="line-height:1.1; color:rgb(64,64,64); margin:30px 0px 10px; font-size:24px"><a name="t9" target="_blank"></a>
4.3 Flags参数<a target="_blank" class="anchorjs-link " href="http://gityuan.com/2016/02/27/am-command/#flags" style=""></a></h3>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
在参数类型1中,提到有<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">-f <FLAGS></code>,是通过<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">Intent.setFlags(int
 )</code>方法,来设置Intent的flags.本小节也是关于flags,是通过<code class="highlighter-rouge" style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:14.4px; padding:2px 4px; color:rgb(199,37,78); background-color:rgb(249,242,244)">Intent.addFlags(int )</code>方法。如下所示,所有的flags参数。</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">[--grant-read-uri-permission] [--grant-write-uri-permission]
[--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
[--debug-log-resolution]
[--exclude-stopped-packages] [--include-stopped-packages]
[--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] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
</code></pre>
</div>
<p style="margin-top:30px; margin-bottom:30px; color:rgb(64,64,64); font-size:16px; line-height:27.2px">
例如,发送action=”broadcast.demo”的广播,并且对于forceStopPackage()的应用不允许接收该广播,命令如下:</p>
<div class="highlighter-rouge" style="color:rgb(64,64,64); font-size:16px; line-height:27.2px">
<pre class="highlight" style="overflow:auto; font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:13px; padding:6px 10px; margin-top:0px; margin-bottom:10px; line-height:1.42857; color:rgb(51,51,51); word-break:break-all; word-wrap:break-word; border:1px solid rgb(204,204,204); background-color:rgb(248,248,248)" name="code"><code style="font-family:Menlo,Monaco,Consolas,'Courier New',monospace; font-size:undefined; padding:0px; color:inherit; display:block; width:auto; word-wrap:normal; background-color:transparent">am broadcast -a broadcast.demo --exclude-stopped-packages
</code><div>
</div></pre>
</div>
   
</div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值