blob: 41bef2223aa8fc2c03c423da994a053314b6fa25 [file] [log] [blame]
Luan Nguyen1afb2d52015-01-16 08:21:57 -08001page.title=ADB Shell Commands
2parent.title=Tools
3parent.link=index.html
4page.tags=shell,adb,am,pm,screenrecord,screencap
5@jd:body
6
7<div id="qv-wrapper">
8<div id="qv">
9 <h2>In this document</h2>
10<ol>
11 <li><a href="#shellcommands">Issuing Shell Commands</a>
12 <li><a href="#am">Using activity manager (am)</a></li>
13 <li><a href="#pm">Using package manager (pm)</a></li>
14 <li><a href="#screencap">Taking a device screenshot</a></li>
15 <li><a href="#screenrecord">Recording a device screen</a></li>
16 <li><a href="#othershellcommands">Other shell commands</a></li>
17 </li>
18</ol>
19
20</div>
21</div>
22
23<p>The <a href="{@docRoot}tools/help/adb.html">Android Debug Bridge</a> (adb) provides a Unix shell
24that you can use to run a variety of commands on an emulator or connected device. The command
25binaries are stored in the file system of the emulator or device, at <code>/system/bin/...</code>
26</p>
27
28<h2 id="shellcommands">Issuing Shell Commands</h2>
29
30<p>You can use the <code>shell</code> command to issue commands, with or without entering
31the adb remote shell on the emulator/device. To issue a single command without entering a
32remote shell, use the <code>shell</code> command like this: </p>
33
34 <pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell &lt;shell_command&gt;</pre>
35
36<p>Or enter a remote shell on an emulator/device like this:</p>
37
38 <pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell</pre>
39
40<p>When you are ready to exit the remote shell, press CTRL+D or type
41<code>exit</code>. </p>
42
43
44
45
46
47<h2 id="am">Using activity manager (am)</h2>
48
49<p>Within an adb shell, you can issue commands with the activity manager ({@code am}) tool to
50perform various system actions, such as start an activity, force-stop a process,
51broadcast an intent, modify the device screen properties, and more. While in a shell,
52the syntax is:</p>
53<pre class="no-pretty-print">
54am &lt;command>
55</pre>
56
57<p>You can also issue an activity manager command directly from adb
58without entering a remote shell. For example:</p>
59<pre class="no-pretty-print">
60adb shell am start -a android.intent.action.VIEW
61</pre>
62
63
64<p class="table-caption"><strong>Table 2.</strong> Available activity manager commands</p>
65<table>
66<tr>
67 <th>Command</th>
68 <th>Description</th>
69</tr>
70
71<tr>
72<td><code>
73start [options] &lt;INTENT>
74</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +000075<td>Start an {@link android.app.Activity} specified by {@code <INTENT>}. <p>See the
Luan Nguyen1afb2d52015-01-16 08:21:57 -080076<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
77<p>Options are:
78<ul>
79 <li>{@code -D}: Enable debugging.
80 <li>{@code -W}: Wait for launch to complete.
Neil Fuller71fbb812015-11-30 09:51:33 +000081 <li>{@code --start-profiler <FILE>}: Start profiler and send results to {@code <FILE>}.
82 <li>{@code -P <FILE>}: Like <code>--start-profiler</code>,
Luan Nguyen1afb2d52015-01-16 08:21:57 -080083 but profiling stops when the app goes idle.
Neil Fuller71fbb812015-11-30 09:51:33 +000084 <li>{@code -R}: Repeat the activity launch {@code <COUNT>} times. Prior to each repeat,
Luan Nguyen1afb2d52015-01-16 08:21:57 -080085 the top activity will be finished.
86 <li>{@code -S}: Force stop the target app before starting the activity.
87 <li>{@code --opengl-trace}: Enable tracing of OpenGL functions.
Neil Fuller71fbb812015-11-30 09:51:33 +000088 <li>{@code --user <USER_ID> | current}: Specify which user to run as; if not
Luan Nguyen1afb2d52015-01-16 08:21:57 -080089 specified, then run as the current user.
90</ul>
91</td>
92</tr>
93
94<tr>
95<td><code>
96startservice [options] &lt;INTENT>
97</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +000098<td>Start the {@link android.app.Service} specified by {@code <INTENT>}. <p>See the
Luan Nguyen1afb2d52015-01-16 08:21:57 -080099<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
100<p>Options are:
101<ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000102 <li>{@code --user <USER_ID> | current}: Specify which user to run as; if not
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800103 specified, then run as the current user.
104</ul>
105</td>
106</tr>
107
108<tr>
109<td><code>
110force-stop &lt;PACKAGE>
111</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000112<td>Force stop everything associated with {@code <PACKAGE>} (the app's package name).
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800113</td>
114</tr>
115
116<tr>
117<td><code>
118kill [options] &lt;PACKAGE>
119</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000120<td> Kill all processes associated with {@code <PACKAGE>}
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800121 (the app's package name). This command kills only
122 processes that are safe to kill and that will not impact the user
123 experience.
124 <p>Options are:
125 <ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000126 <li>{@code --user <USER_ID> | all | current}: Specify user whose processes to kill;
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800127 all users if not specified.
128 </ul>
129</td>
130</tr>
131
132<tr>
133<td><code>
134kill-all
135</code></td>
136<td>Kill all background processes.
137</td>
138</tr>
139
140<tr>
141<td><code>
142broadcast [options] &lt;INTENT>
143</code></td>
144<td>Issue a broadcast intent. <p>See the
145<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
146<p>Options are:
147<ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000148 <li>{@code [--user <USER_ID> | all | current]}: Specify which user to send to; if not
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800149 specified then send to all users.
150</ul>
151</td>
152</tr>
153
154<tr>
155<td><code>
156instrument [options] &lt;COMPONENT>
157</code></td>
158<td>Start monitoring with an {@link android.app.Instrumentation} instance.
Neil Fuller71fbb812015-11-30 09:51:33 +0000159 Typically the target {@code <COMPONENT>}
160 is the form {@code <TEST_PACKAGE>/<RUNNER_CLASS>}. <p>Options are:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800161<ul>
162 <li>{@code -r}: Print raw results (otherwise decode
Neil Fuller71fbb812015-11-30 09:51:33 +0000163 {@code <REPORT_KEY_STREAMRESULT>}). Use with
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800164 {@code [-e perf true]} to generate raw output for performance measurements.
165
Neil Fuller71fbb812015-11-30 09:51:33 +0000166 <li>{@code -e <NAME> <VALUE>}: Set argument {@code <NAME>} to {@code <VALUE>}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800167 For test runners a common form is {@code
Neil Fuller71fbb812015-11-30 09:51:33 +0000168 -e <testrunner_flag> <value>[,<value>...]}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800169
Neil Fuller71fbb812015-11-30 09:51:33 +0000170 <li>{@code -p <FILE>}: Write profiling data to {@code <FILE>}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800171
172 <li>{@code -w}: Wait for instrumentation to finish before returning. Required for
173 test runners.
174
175 <li>{@code --no-window-animation}: Turn off window animations while running.
Neil Fuller71fbb812015-11-30 09:51:33 +0000176 <li>{@code --user <USER_ID> | current}: Specify which user instrumentation runs in;
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800177 current user if not specified.
178</ul>
179
180</td>
181</tr>
182
183<tr>
184<td><code>
185profile start &lt;PROCESS> &lt;FILE>
186</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000187<td>Start profiler on {@code <PROCESS>}, write results to {@code <FILE>}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800188</td>
189</tr>
190
191<tr>
192<td><code>
193profile stop &lt;PROCESS>
194</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000195<td>Stop profiler on {@code <PROCESS>}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800196</td>
197</tr>
198
199<tr>
200<td style="white-space:nowrap"><code>
201dumpheap [options] &lt;PROCESS> &lt;FILE>
202</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000203<td>Dump the heap of {@code <PROCESS>}, write to {@code <FILE>}. <p>Options are:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800204<ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000205 <li>{@code --user [<USER_ID>|current]}: When supplying a process name,
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800206 specify user of process to dump; uses current user if not specified.
207 <li>{@code -n}: Dump native heap instead of managed heap.
208</ul>
209</td>
210</tr>
211
212<tr>
213<td><code>
214set-debug-app [options] &lt;PACKAGE>
215</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000216<td>Set application {@code <PACKAGE>} to debug. <p>Options are:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800217<ul>
218 <li>{@code -w}: Wait for debugger when application starts.
219 <li>{@code --persistent}: Retain this value.
220</ul>
221</td>
222</tr>
223
224<tr>
225<td><code>
226clear-debug-app
227</code></td>
228<td>Clear the package previous set for debugging with {@code set-debug-app}.
229</td>
230</tr>
231
232<tr>
233<td><code>
234monitor [options]
235</code></td>
236<td>Start monitoring for crashes or ANRs. <p>Options are:
237<ul>
238 <li>{@code --gdb}: Start gdbserv on the given port at crash/ANR.
239</ul>
240</td>
241</tr>
242
243<tr>
244<td><code>
245screen-compat [on|off] &lt;PACKAGE>
246</code></td>
247<td>Control <a href="{@docRoot}guide/practices/screen-compat-mode.html">screen
Neil Fuller71fbb812015-11-30 09:51:33 +0000248compatibility</a> mode of {@code <PACKAGE>}.</p>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800249</td>
250</tr>
251
252<tr>
253<td><code>
254display-size [reset|&lt;WxH>]
255</code></td>
256<td>Override emulator/device display size.
257This command is helpful for testing your app across different screen sizes by mimicking a small
258screen resolution using a device with a large screen, and vice versa.
259<p>Example:<br><code>am display-size 1280x800</code>
260</td>
261</tr>
262
263<tr>
264<td><code>
265display-density &lt;dpi>
266</code></td>
267<td>Override emulator/device display density.
268This command is helpful for testing your app across different screen densities on high-density
269screen environment using a low density screen, and vice versa.
270<p>Example:<br><code>am display-density 480</code>
271</td>
272</tr>
273
274<tr>
275<td><code>
276to-uri &lt;INTENT>
277</code></td>
278<td>Print the given intent specification as a URI. <p>See the
279<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
280</td>
281</tr>
282
283<tr>
284<td><code>
285to-intent-uri &lt;INTENT>
286</code></td>
287<td>Print the given intent specification as an {@code intent:} URI. <p>See the
288<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
289</td>
290</tr>
291</table>
292
293
294
295
296
297<h3 id="IntentSpec">
298 <a href="" class="expandable" onclick="toggleExpandable(this,'.intents');
299return false">Specification for &lt;INTENT> arguments</a></h3>
300
301<div class="intents" style="display:none">
302
Neil Fuller71fbb812015-11-30 09:51:33 +0000303<p>For activity manager commands that take a {@code <INTENT>} argument, you can
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800304specify the intent with the following options:</p>
305
306<dl>
Neil Fuller71fbb812015-11-30 09:51:33 +0000307 <dt>{@code -a <ACTION>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800308 <dd>Specify the intent action, such as "android.intent.action.VIEW".
309 You can declare this only once.
310
Neil Fuller71fbb812015-11-30 09:51:33 +0000311 <dt>{@code -d <DATA_URI>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800312 <dd>Specify the intent data URI, such as "content://contacts/people/1".
313 You can declare this only once.
314
Neil Fuller71fbb812015-11-30 09:51:33 +0000315 <dt>{@code -t <MIME_TYPE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800316 <dd>Specify the intent MIME type, such as "image/png".
317 You can declare this only once.
318
Neil Fuller71fbb812015-11-30 09:51:33 +0000319 <dt>{@code -c <CATEGORY>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800320 <dd>Specify an intent category, such as "android.intent.category.APP_CONTACTS".
321
Neil Fuller71fbb812015-11-30 09:51:33 +0000322 <dt>{@code -n <COMPONENT>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800323 <dd>Specify the component name with package name prefix to create an explicit intent, such
324 as "com.example.app/.ExampleActivity".
325
Neil Fuller71fbb812015-11-30 09:51:33 +0000326 <dt>{@code -f <FLAGS>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800327 <dd>Add flags to the intent, as supported by {@link
328 android.content.Intent#setFlags setFlags()}.
329
Neil Fuller71fbb812015-11-30 09:51:33 +0000330 <dt>{@code --esn <EXTRA_KEY>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800331 <dd>Add a null extra. This option is not supported for URI intents.
332
Neil Fuller71fbb812015-11-30 09:51:33 +0000333 <dt>{@code -e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800334 <dd>Add string data as a key-value pair.
335
Neil Fuller71fbb812015-11-30 09:51:33 +0000336 <dt>{@code --ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800337 <dd>Add boolean data as a key-value pair.
338
Neil Fuller71fbb812015-11-30 09:51:33 +0000339 <dt>{@code --ei <EXTRA_KEY> <EXTRA_INT_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800340 <dd>Add integer data as a key-value pair.
341
Neil Fuller71fbb812015-11-30 09:51:33 +0000342 <dt>{@code --el <EXTRA_KEY> <EXTRA_LONG_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800343 <dd>Add long data as a key-value pair.
344
Neil Fuller71fbb812015-11-30 09:51:33 +0000345 <dt>{@code --ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800346 <dd>Add float data as a key-value pair.
347
Neil Fuller71fbb812015-11-30 09:51:33 +0000348 <dt>{@code --eu <EXTRA_KEY> <EXTRA_URI_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800349 <dd>Add URI data as a key-value pair.
350
Neil Fuller71fbb812015-11-30 09:51:33 +0000351 <dt>{@code --ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800352 <dd>Add a component name, which is converted and passed as
353 a {@link android.content.ComponentName} object.
354
Neil Fuller71fbb812015-11-30 09:51:33 +0000355 <dt>{@code --eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800356 <dd>Add an array of integers.
357
Neil Fuller71fbb812015-11-30 09:51:33 +0000358 <dt>{@code --ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800359 <dd>Add an array of longs.
360
Neil Fuller71fbb812015-11-30 09:51:33 +0000361 <dt>{@code --efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800362 <dd>Add an array of floats.
363
364 <dt>{@code --grant-read-uri-permission}</dt>
365 <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}.
366
367 <dt>{@code --grant-write-uri-permission}</dt>
368 <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}.
369
370 <dt>{@code --debug-log-resolution}</dt>
371 <dd>Include the flag {@link android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION}.
372
373 <dt>{@code --exclude-stopped-packages}</dt>
374 <dd>Include the flag {@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES}.
375
376 <dt>{@code --include-stopped-packages}</dt>
377 <dd>Include the flag {@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES}.
378
379 <dt>{@code --activity-brought-to-front}</dt>
380 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT}.
381
382 <dt>{@code --activity-clear-top}</dt>
383 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}.
384
385 <dt>{@code --activity-clear-when-task-reset}</dt>
386 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET}.
387
388 <dt>{@code --activity-exclude-from-recents}</dt>
389 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS}.
390
391 <dt>{@code --activity-launched-from-history}</dt>
392 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY}.
393
394 <dt>{@code --activity-multiple-task}</dt>
395 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}.
396
397 <dt>{@code --activity-no-animation}</dt>
398 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION}.
399
400 <dt>{@code --activity-no-history}</dt>
401 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_HISTORY}.
402
403 <dt>{@code --activity-no-user-action}</dt>
404 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION}.
405
406 <dt>{@code --activity-previous-is-top}</dt>
407 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP}.
408
409 <dt>{@code --activity-reorder-to-front}</dt>
410 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT}.
411
412 <dt>{@code --activity-reset-task-if-needed}</dt>
413 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED}.
414
415 <dt>{@code --activity-single-top}</dt>
416 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}.
417
418 <dt>{@code --activity-clear-task}</dt>
419 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK}.
420
421 <dt>{@code --activity-task-on-home}</dt>
422 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME}.
423
424 <dt>{@code --receiver-registered-only}</dt>
425 <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY}.
426
427 <dt>{@code --receiver-replace-pending}</dt>
428 <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING}.
429
430 <dt>{@code --selector}</dt>
431 <dd>Requires the use of {@code -d} and {@code -t} options to set the intent data and type.
432
Neil Fuller71fbb812015-11-30 09:51:33 +0000433 <dt>{@code <URI> <COMPONENT> <PACKAGE>}</dt>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800434 <dd>You can directly specify a URI, package name, and component name when not qualified
435 by one of the above options. When an argument is unqualified, the tool assumes the argument
436 is a URI if it contains a ":" (colon); it assumes the argument is a component name if it
437 contains a "/" (forward-slash); otherwise it assumes the argument is a package name.
438
439</dl>
440</div><!-- end 'intents' -->
441<script>
442 $(window).hashchange( function(){
443 if ((location.hash == "#IntentSpec") && !($("#IntentSpec a").hasClass("expanded"))) {
444 $("#IntentSpec a").click();
445 }
446 });
447</script>
448
449
450
451<h2 id="pm">Using package manager (pm)</h2>
452
453<p>Within an adb shell, you can issue commands with the package manager ({@code pm}) tool to
454perform actions and queries on application packages installed on the device. While in a shell,
455the syntax is:</p>
456<pre class="no-pretty-print">
457pm &lt;command>
458</pre>
459
460<p>You can also issue a package manager command directly from adb
461without entering a remote shell. For example:</p>
462<pre class="no-pretty-print">
463adb shell pm uninstall com.example.MyApp
464</pre>
465
466<p class="table-caption"><strong>Table 3.</strong> Available package manager commands.</p>
467<table>
468<tr>
469 <th>Command</th>
470 <th>Description</th>
471</tr>
472
473<tr>
474<td><code>
475list packages [options] &lt;FILTER>
476</code></td>
477<td>Prints all packages, optionally only
Neil Fuller71fbb812015-11-30 09:51:33 +0000478 those whose package name contains the text in {@code <FILTER>}. <p>Options:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800479<ul>
480 <li>{@code -f}: See their associated file.
481 <li>{@code -d}: Filter to only show disabled packages.
482 <li>{@code -e}: Filter to only show enabled packages.
483 <li>{@code -s}: Filter to only show system packages.
484 <li>{@code -3}: Filter to only show third party packages.
485 <li>{@code -i}: See the installer for the packages.
486 <li>{@code -u}: Also include uninstalled packages.
Neil Fuller71fbb812015-11-30 09:51:33 +0000487 <li>{@code --user <USER_ID>}: The user space to query.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800488</ul>
489</td>
490</tr>
491
492<tr>
493<td><code>
494list permission-groups
495</code></td>
496<td>Prints all known permission groups.
497</td>
498</tr>
499
500<tr>
501<td><code>
502list permissions [options] &lt;GROUP>
503</code></td>
504<td>Prints all known permissions, optionally only
Neil Fuller71fbb812015-11-30 09:51:33 +0000505 those in {@code <GROUP>}. <p>Options:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800506<ul>
507 <li>{@code -g}: Organize by group.
508 <li>{@code -f}: Print all information.
509 <li>{@code -s}: Short summary.
510 <li>{@code -d}: Only list dangerous permissions.
511 <li>{@code -u}: List only the permissions users will see.
512</ul>
513</td>
514</tr>
515
516<tr>
517<td><code>
518list instrumentation
519</code></td>
520<td>List all test packages. <p>Options:
521 <ul>
522 <li>{@code -f}: List the APK file for the test package.
Neil Fuller71fbb812015-11-30 09:51:33 +0000523 <li>{@code <TARGET_PACKAGE>}: List test packages for only this app.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800524 </ul>
525</td>
526</tr>
527
528<tr>
529<td><code>
530list features
531</code></td>
532<td>Prints all features of the system.
533</td>
534</tr>
535
536<tr>
537<td><code>
538list libraries
539</code></td>
540<td>Prints all the libraries supported by the current device.
541</td>
542</tr>
543
544<tr>
545<td><code>
546list users
547</code></td>
548<td>Prints all users on the system.
549</td>
550</tr>
551
552<tr>
553<td><code>
554path &lt;PACKAGE>
555</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000556<td>Print the path to the APK of the given {@code <PACKAGE>}.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800557</td>
558</tr>
559
560<tr>
561<td><code>
562install [options] &lt;PATH>
563</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000564<td>Installs a package (specified by {@code <PATH>}) to the system. <p>Options:
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800565 <ul>
566 <li>{@code -l}: Install the package with forward lock.
567 <li>{@code -r}: Reinstall an exisiting app, keeping its data.
568 <li>{@code -t}: Allow test APKs to be installed.
Neil Fuller71fbb812015-11-30 09:51:33 +0000569 <li>{@code -i <INSTALLER_PACKAGE_NAME>}: Specify the installer package name.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800570 <li>{@code -s}: Install package on the shared mass storage (such as sdcard).
571 <li>{@code -f}: Install package on the internal system memory.
572 <li>{@code -d}: Allow version code downgrade.
573 </ul>
574</td>
575</tr>
576
577<tr>
578<td><code>
579uninstall [options] &lt;PACKAGE>
580</code></td>
581<td>Removes a package from the system. <p>Options:
582 <ul>
583 <li>{@code -k}: Keep the data and cache directories around after package removal.
584 </ul>
585</td>
586</tr>
587
588<tr>
589<td><code>
590clear &lt;PACKAGE>
591</code></td>
592<td>Deletes all data associated with a package.
593</td>
594</tr>
595
596<tr>
597<td><code>
598enable &lt;PACKAGE_OR_COMPONENT>
599</code></td>
600<td>Enable the given package or component (written as "package/class").
601</td>
602</tr>
603
604<tr>
605<td><code>
606disable &lt;PACKAGE_OR_COMPONENT>
607</code></td>
608<td>Disable the given package or component (written as "package/class").
609</td>
610</tr>
611
612<tr>
613<td style="white-space:nowrap"><code>
614disable-user [options] &lt;PACKAGE_OR_COMPONENT>
615</code></td>
616<td><p>Options:
617 <ul>
Neil Fuller71fbb812015-11-30 09:51:33 +0000618 <li>{@code --user <USER_ID>}: The user to disable.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800619 </ul>
620</td>
621</tr>
622
623<tr>
624<td><code>
625grant &lt;PACKAGE_PERMISSION>
626</code></td>
627<td>Grant permissions
628 to applications. Only optional permissions the application has
629 declared can be granted.
630</td>
631</tr>
632
633<tr>
634<td><code>
635revoke &lt;PACKAGE_PERMISSION>
636</code></td>
637<td>Revoke permissions
638 to applications. Only optional permissions the application has
639 declared can be revoked.
640</td>
641</tr>
642
643<tr>
644<td><code>
645set-install-location &lt;LOCATION>
646</code></td>
647<td>Changes the default install location. Location values:
648<ul>
649 <li>{@code 0}: Auto&mdash;Let system decide the best location.
650 <li>{@code 1}: Internal&mdash;install on internal device storage.
651 <li>{@code 2}: External&mdash;install on external media.
652</ul>
653<p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause
654 applications to break and other undesireable behavior.</p>
655</td>
656</tr>
657
658<tr>
659<td><code>
660get-install-location
661</code></td>
662<td>Returns the current install location. Return values:
663<ul>
664 <li>{@code 0 [auto]}: Lets system decide the best location
665 <li>{@code 1 [internal]}: Installs on internal device storage
666 <li>{@code 2 [external]}: Installs on external media
667</ul>
668</td>
669</tr>
670
671<tr>
672<td><code>
673set-permission-enforced &lt;PERMISSION> [true|false]
674</code></td>
675<td>Specifies whether the given permission should be enforced.
676</td>
677</tr>
678
679<tr>
680<td><code>
681trim-caches &lt;DESIRED_FREE_SPACE>
682</code></td>
683<td>Trim cache files to reach the given free space.
684</td>
685</tr>
686
687<tr>
688<td><code>
689create-user &lt;USER_NAME>
690</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000691<td>Create a new user with the given {@code <USER_NAME>},
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800692 printing the new user identifier of the user.
693</td>
694</tr>
695
696<tr>
697<td><code>
698remove-user &lt;USER_ID>
699</code></td>
Neil Fuller71fbb812015-11-30 09:51:33 +0000700<td>Remove the user with the given {@code <USER_IDENTIFIER>},
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800701 deleting all data associated with that user
702</td>
703</tr>
704
705<tr>
706<td><code>
707get-max-users
708</code></td>
709<td>Prints the maximum number of users supported by the device.
710</td>
711</tr>
712
713</table>
714
715
716<h2 id="screencap">Taking a device screenshot</h2>
717
718<p>The {@code screencap} command is a shell utility for taking a screenshot of a device display.
719While in a shell, the syntax is:
720</p>
721
722<pre class="no-pretty-print">
723screencap &lt;filename>
724</pre>
725
726
727<p>To use the {@code screencap} from the command line, type the following:
728
729<pre>
730$ adb shell screencap /sdcard/screen.png
731</pre>
732
733<p>Here's an example screenshot session, using the adb shell to capture the screenshot and the
734{@code pull} command to download the file from the device:<p>
735
736<pre>
737$ adb shell
738shell@ $ screencap /sdcard/screen.png
739shell@ $ exit
740$ adb pull /sdcard/screen.png
741</pre>
742
743
744<h2 id="screenrecord">Recording a device screen</h2>
745
746<p>The {@code screenrecord} command is a shell utility for recording the display of devices
747 running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4
748 file.</p>
749
750<p class="note"><strong>Note:</strong> Audio is not recorded with the video file.</p>
751
752<p>A developer can use this file to create promotional or training videos. While in a shell, the syntax is:</p>
753
754<pre class="no-pretty-print">
755screenrecord [options] &lt;filename>
756</pre>
757
758<p>To use {@code screenrecord} from the command line, type the following:
759
760<pre>
761$ adb shell screenrecord /sdcard/demo.mp4
762</pre>
763
764<p>Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically
765at three minutes or the time limit set by {@code --time-limit}.</p>
766
767<p>To begin recording your device screen, run the {@code screenrecord} command to record
768the video. Then, run the {@code pull} command to download the video from the device to the host
769computer. Here's an example recording session:<p>
770
771<pre>
772$ adb shell
773shell@ $ screenrecord --verbose /sdcard/demo.mp4
774(press Ctrl-C to stop)
775shell@ $ exit
776$ adb pull /sdcard/demo.mp4
777</pre>
778
779<p>The {@code screenrecord} utility can record at any supported resolution and bit rate you
780 request, while retaining the aspect ratio of the device display. The utility records at the native
781 display resolution and orientation by default, with a maximum length of three minutes.</p>
782
783<p>There are some known limitations of the {@code screenrecord} utility that you should be aware
784 of when using it:</p>
785
786<ul>
787 <li>Some devices may not be able to record at their native display resolution.
788 If you encounter problems with screen recording, try using a lower screen resolution.</li>
789 <li>Rotation of the screen during recording is not supported. If the screen does rotate during
790 recording, some of the screen is cut off in the recording.</li>
791</ul>
792
793
794<p class="table-caption"><strong>Table 4.</strong> {@code screenrecord} options</p>
795
796<table>
797 <tr>
798 <th>Options</th>
799 <th>Description</th>
800 </tr>
801
802 <tr>
803 <td><code>--help</code>
804 </td>
805 <td>Displays command syntax and options</td>
806 </tr>
807
808 <tr>
809 <td style="white-space:nowrap">
810 <code>--size &lt;WIDTHxHEIGHT&gt;</code>
811 </td>
812 <td>Sets the video size: {@code 1280x720}. The default value is the device's native
813 display resolution (if supported), 1280x720 if not. For best results, use a size supported
814 by your device's Advanced Video Coding (AVC) encoder.</td>
815 </tr>
816
817 <tr>
818 <td><code>--bit-rate &lt;RATE&gt;</code></td>
819 <td>Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps.
820 You can increase the bit rate to improve video quality, but doing so results in larger movie
821 files. The following example sets the recording bit rate to 6Mbps:
822 <pre>screenrecord --bit-rate 6000000 &#47;sdcard&#47;demo.mp4</pre>
823 </td>
824 </tr>
825
826 <tr>
827 <td><code>--time-limit &lt;TIME&gt;</code></td>
828 <td>Sets the maximum recording time, in seconds. The default and maximum value is 180
829 (3 minutes).</td>
830 </tr>
831
832 <tr>
833 <td><code>--rotate</code></td>
834 <td>Rotates the output 90 degrees. This feature is experimental.</td>
835 </tr>
836
837 <tr>
838 <td><code>--verbose</code></td>
839 <td>Displays log information on the command-line screen. If you do not set this option,
840 the utility does not display any information while running.</td>
841 </tr>
842
843</table>
844
845
846<h2 id="othershellcommands">Other shell commands</h2>
847
848<p>For a list of all the available shell programs, use the following command:</p>
849
850<pre class="no-pretty-print">adb shell ls /system/bin</pre>
851
852<p>Help is available for most of the commands. </p>
853
854<p>Table 5 lists some of the more common adb shell commands.</p>
855
856<p class="table-caption"><strong>Table 5.</strong> Some other adb shell commands</p>
857<table>
858<tr>
859 <th>Shell Command</th>
860 <th>Description</th>
861 <th>Comments</th>
862</tr>
863
864<tr>
865<td><code>dumpsys</code></td>
866<td>Dumps system data to the screen.</td>
867<td rowspan=4">The <a href="{@docRoot}tools/debugging/ddms.html">Dalvik Debug Monitor Server</a>
868(DDMS) tool offers integrated debug environment that you may find easier to use.</td>
869</tr>
870
871<tr>
872<td><code>dumpstate</code></td>
873<td>Dumps state to a file.</td>
874</tr>
875
876<tr>
877<td><code>logcat&nbsp;[option]...&nbsp;[filter-spec]...</code></td>
878<td>Enables system and app logging and prints output to the screen. </td>
879</tr>
880
881<tr>
882<td><code>dmesg</code></td>
883<td>Prints kernel debugging messages to the screen. </td>
884</tr>
885
886<tr>
887<td><code>start</code></td>
888<td>Starts (restarts) an emulator/device instance.</td>
889<td>&nbsp;</td>
890</tr>
891
892<tr>
893<td><code>stop</code></td>
894<td>Stops execution of an emulator/device instance.</td>
895<td>&nbsp;</td>
896</tr>
897
898</table>