blob: 40f07719720efb7a7e4662858548de4a09339f33 [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>
75<td>Start an {@link android.app.Activity} specified by {@code &lt;INTENT>}. <p>See the
76<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.
81 <li>{@code --start-profiler &lt;FILE>}: Start profiler and send results to {@code &lt;FILE>}.
82 <li>{@code -P &lt;FILE>}: Like <code>--start-profiler</code>,
83 but profiling stops when the app goes idle.
84 <li>{@code -R}: Repeat the activity launch {@code &lt;COUNT>} times. Prior to each repeat,
85 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.
88 <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
89 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>
98<td>Start the {@link android.app.Service} specified by {@code &lt;INTENT>}. <p>See the
99<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
100<p>Options are:
101<ul>
102 <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
103 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>
112<td>Force stop everything associated with {@code &lt;PACKAGE>} (the app's package name).
113</td>
114</tr>
115
116<tr>
117<td><code>
118kill [options] &lt;PACKAGE>
119</code></td>
120<td> Kill all processes associated with {@code &lt;PACKAGE>}
121 (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>
126 <li>{@code --user &lt;USER_ID> | all | current}: Specify user whose processes to kill;
127 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>
148 <li>{@code [--user &lt;USER_ID> | all | current]}: Specify which user to send to; if not
149 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.
159 Typically the target {@code &lt;COMPONENT>}
160 is the form {@code &lt;TEST_PACKAGE>/&lt;RUNNER_CLASS>}. <p>Options are:
161<ul>
162 <li>{@code -r}: Print raw results (otherwise decode
163 {@code &lt;REPORT_KEY_STREAMRESULT>}). Use with
164 {@code [-e perf true]} to generate raw output for performance measurements.
165
166 <li>{@code -e &lt;NAME> &lt;VALUE>}: Set argument {@code &lt;NAME>} to {@code &lt;VALUE>}.
167 For test runners a common form is {@code
168 -e &lt;testrunner_flag> &lt;value>[,&lt;value>...]}.
169
170 <li>{@code -p &lt;FILE>}: Write profiling data to {@code &lt;FILE>}.
171
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.
176 <li>{@code --user &lt;USER_ID> | current}: Specify which user instrumentation runs in;
177 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>
187<td>Start profiler on {@code &lt;PROCESS>}, write results to {@code &lt;FILE>}.
188</td>
189</tr>
190
191<tr>
192<td><code>
193profile stop &lt;PROCESS>
194</code></td>
195<td>Stop profiler on {@code &lt;PROCESS>}.
196</td>
197</tr>
198
199<tr>
200<td style="white-space:nowrap"><code>
201dumpheap [options] &lt;PROCESS> &lt;FILE>
202</code></td>
203<td>Dump the heap of {@code &lt;PROCESS>}, write to {@code &lt;FILE>}. <p>Options are:
204<ul>
205 <li>{@code --user [&lt;USER_ID>|current]}: When supplying a process name,
206 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>
216<td>Set application {@code &lt;PACKAGE>} to debug. <p>Options are:
217<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
248compatibility</a> mode of {@code &lt;PACKAGE>}.</p>
249</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
303<p>For activity manager commands that take a {@code &lt;INTENT>} argument, you can
304specify the intent with the following options:</p>
305
306<dl>
307 <dt>{@code -a &lt;ACTION>}</dt>
308 <dd>Specify the intent action, such as "android.intent.action.VIEW".
309 You can declare this only once.
310
311 <dt>{@code -d &lt;DATA_URI>}</dt>
312 <dd>Specify the intent data URI, such as "content://contacts/people/1".
313 You can declare this only once.
314
315 <dt>{@code -t &lt;MIME_TYPE>}</dt>
316 <dd>Specify the intent MIME type, such as "image/png".
317 You can declare this only once.
318
319 <dt>{@code -c &lt;CATEGORY>}</dt>
320 <dd>Specify an intent category, such as "android.intent.category.APP_CONTACTS".
321
322 <dt>{@code -n &lt;COMPONENT>}</dt>
323 <dd>Specify the component name with package name prefix to create an explicit intent, such
324 as "com.example.app/.ExampleActivity".
325
326 <dt>{@code -f &lt;FLAGS>}</dt>
327 <dd>Add flags to the intent, as supported by {@link
328 android.content.Intent#setFlags setFlags()}.
329
330 <dt>{@code --esn &lt;EXTRA_KEY>}</dt>
331 <dd>Add a null extra. This option is not supported for URI intents.
332
333 <dt>{@code -e|--es &lt;EXTRA_KEY> &lt;EXTRA_STRING_VALUE>}</dt>
334 <dd>Add string data as a key-value pair.
335
336 <dt>{@code --ez &lt;EXTRA_KEY> &lt;EXTRA_BOOLEAN_VALUE>}</dt>
337 <dd>Add boolean data as a key-value pair.
338
339 <dt>{@code --ei &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>}</dt>
340 <dd>Add integer data as a key-value pair.
341
342 <dt>{@code --el &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>}</dt>
343 <dd>Add long data as a key-value pair.
344
345 <dt>{@code --ef &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>}</dt>
346 <dd>Add float data as a key-value pair.
347
348 <dt>{@code --eu &lt;EXTRA_KEY> &lt;EXTRA_URI_VALUE>}</dt>
349 <dd>Add URI data as a key-value pair.
350
351 <dt>{@code --ecn &lt;EXTRA_KEY> &lt;EXTRA_COMPONENT_NAME_VALUE>}</dt>
352 <dd>Add a component name, which is converted and passed as
353 a {@link android.content.ComponentName} object.
354
355 <dt>{@code --eia &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>[,&lt;EXTRA_INT_VALUE...]}</dt>
356 <dd>Add an array of integers.
357
358 <dt>{@code --ela &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>[,&lt;EXTRA_LONG_VALUE...]}</dt>
359 <dd>Add an array of longs.
360
361 <dt>{@code --efa &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>[,&lt;EXTRA_FLOAT_VALUE...]}</dt>
362 <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
433 <dt>{@code &lt;URI> &lt;COMPONENT> &lt;PACKAGE>}</dt>
434 <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
478 those whose package name contains the text in {@code &lt;FILTER>}. <p>Options:
479<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.
487 <li>{@code --user &lt;USER_ID>}: The user space to query.
488</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
505 those in {@code &lt;GROUP>}. <p>Options:
506<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.
523 <li>{@code &lt;TARGET_PACKAGE>}: List test packages for only this app.
524 </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>
556<td>Print the path to the APK of the given {@code &lt;PACKAGE>}.
557</td>
558</tr>
559
560<tr>
561<td><code>
562install [options] &lt;PATH>
563</code></td>
564<td>Installs a package (specified by {@code &lt;PATH>}) to the system. <p>Options:
565 <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.
569 <li>{@code -i &lt;INSTALLER_PACKAGE_NAME>}: Specify the installer package name.
570 <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.
Andrew Solovay5d9e27e2015-09-11 14:52:33 -0700573 <li>{@code -g}: Grant all permissions listed in the app manifest.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800574 </ul>
575</td>
576</tr>
577
578<tr>
579<td><code>
580uninstall [options] &lt;PACKAGE>
581</code></td>
582<td>Removes a package from the system. <p>Options:
583 <ul>
584 <li>{@code -k}: Keep the data and cache directories around after package removal.
585 </ul>
586</td>
587</tr>
588
589<tr>
590<td><code>
591clear &lt;PACKAGE>
592</code></td>
593<td>Deletes all data associated with a package.
594</td>
595</tr>
596
597<tr>
598<td><code>
599enable &lt;PACKAGE_OR_COMPONENT>
600</code></td>
601<td>Enable the given package or component (written as "package/class").
602</td>
603</tr>
604
605<tr>
606<td><code>
607disable &lt;PACKAGE_OR_COMPONENT>
608</code></td>
609<td>Disable the given package or component (written as "package/class").
610</td>
611</tr>
612
613<tr>
614<td style="white-space:nowrap"><code>
615disable-user [options] &lt;PACKAGE_OR_COMPONENT>
616</code></td>
617<td><p>Options:
618 <ul>
619 <li>{@code --user &lt;USER_ID>}: The user to disable.
620 </ul>
621</td>
622</tr>
623
624<tr>
625<td><code>
Andrew Solovay5d9e27e2015-09-11 14:52:33 -0700626grant &lt;PACKAGE_NAME&gt; &lt;PERMISSION&gt;
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800627</code></td>
Andrew Solovay5d9e27e2015-09-11 14:52:33 -0700628<td>Grant a permission to an app. On devices running Android 6.0 (API level 23)
629and higher, may be any permission declared in the app manifest. On devices
630running Android 5.1 (API level 22) and lower, must be an optional permission defined by the
631app.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800632</td>
633</tr>
634
635<tr>
636<td><code>
Andrew Solovay5d9e27e2015-09-11 14:52:33 -0700637revoke &lt;PACKAGE_NAME&gt; &lt;PERMISSION&gt;
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800638</code></td>
Andrew Solovay5d9e27e2015-09-11 14:52:33 -0700639<td>Revoke a permission from an app. On devices running Android 6.0 (API level
64023) and higher, may be any permission declared in the app manifest. On devices
641running Android 5.1 (API level 22) and lower, must be an optional permission defined by the
642app.
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800643</td>
644</tr>
645
646<tr>
647<td><code>
648set-install-location &lt;LOCATION>
649</code></td>
650<td>Changes the default install location. Location values:
651<ul>
652 <li>{@code 0}: Auto&mdash;Let system decide the best location.
653 <li>{@code 1}: Internal&mdash;install on internal device storage.
654 <li>{@code 2}: External&mdash;install on external media.
655</ul>
656<p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause
657 applications to break and other undesireable behavior.</p>
658</td>
659</tr>
660
661<tr>
662<td><code>
663get-install-location
664</code></td>
665<td>Returns the current install location. Return values:
666<ul>
667 <li>{@code 0 [auto]}: Lets system decide the best location
668 <li>{@code 1 [internal]}: Installs on internal device storage
669 <li>{@code 2 [external]}: Installs on external media
670</ul>
671</td>
672</tr>
673
674<tr>
675<td><code>
676set-permission-enforced &lt;PERMISSION> [true|false]
677</code></td>
678<td>Specifies whether the given permission should be enforced.
679</td>
680</tr>
681
682<tr>
683<td><code>
684trim-caches &lt;DESIRED_FREE_SPACE>
685</code></td>
686<td>Trim cache files to reach the given free space.
687</td>
688</tr>
689
690<tr>
691<td><code>
692create-user &lt;USER_NAME>
693</code></td>
694<td>Create a new user with the given {@code &lt;USER_NAME>},
695 printing the new user identifier of the user.
696</td>
697</tr>
698
699<tr>
700<td><code>
701remove-user &lt;USER_ID>
702</code></td>
703<td>Remove the user with the given {@code &lt;USER_IDENTIFIER>},
704 deleting all data associated with that user
705</td>
706</tr>
707
708<tr>
709<td><code>
710get-max-users
711</code></td>
712<td>Prints the maximum number of users supported by the device.
713</td>
714</tr>
715
716</table>
717
718
719<h2 id="screencap">Taking a device screenshot</h2>
720
721<p>The {@code screencap} command is a shell utility for taking a screenshot of a device display.
722While in a shell, the syntax is:
723</p>
724
725<pre class="no-pretty-print">
726screencap &lt;filename>
727</pre>
728
729
730<p>To use the {@code screencap} from the command line, type the following:
731
732<pre>
733$ adb shell screencap /sdcard/screen.png
734</pre>
735
736<p>Here's an example screenshot session, using the adb shell to capture the screenshot and the
737{@code pull} command to download the file from the device:<p>
738
739<pre>
740$ adb shell
741shell@ $ screencap /sdcard/screen.png
742shell@ $ exit
743$ adb pull /sdcard/screen.png
744</pre>
745
746
747<h2 id="screenrecord">Recording a device screen</h2>
748
749<p>The {@code screenrecord} command is a shell utility for recording the display of devices
750 running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4
751 file.</p>
752
753<p class="note"><strong>Note:</strong> Audio is not recorded with the video file.</p>
754
755<p>A developer can use this file to create promotional or training videos. While in a shell, the syntax is:</p>
756
757<pre class="no-pretty-print">
758screenrecord [options] &lt;filename>
759</pre>
760
761<p>To use {@code screenrecord} from the command line, type the following:
762
763<pre>
764$ adb shell screenrecord /sdcard/demo.mp4
765</pre>
766
767<p>Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically
768at three minutes or the time limit set by {@code --time-limit}.</p>
769
770<p>To begin recording your device screen, run the {@code screenrecord} command to record
771the video. Then, run the {@code pull} command to download the video from the device to the host
772computer. Here's an example recording session:<p>
773
774<pre>
775$ adb shell
776shell@ $ screenrecord --verbose /sdcard/demo.mp4
777(press Ctrl-C to stop)
778shell@ $ exit
779$ adb pull /sdcard/demo.mp4
780</pre>
781
782<p>The {@code screenrecord} utility can record at any supported resolution and bit rate you
783 request, while retaining the aspect ratio of the device display. The utility records at the native
784 display resolution and orientation by default, with a maximum length of three minutes.</p>
785
786<p>There are some known limitations of the {@code screenrecord} utility that you should be aware
787 of when using it:</p>
788
789<ul>
790 <li>Some devices may not be able to record at their native display resolution.
791 If you encounter problems with screen recording, try using a lower screen resolution.</li>
792 <li>Rotation of the screen during recording is not supported. If the screen does rotate during
793 recording, some of the screen is cut off in the recording.</li>
794</ul>
795
796
797<p class="table-caption"><strong>Table 4.</strong> {@code screenrecord} options</p>
798
799<table>
800 <tr>
801 <th>Options</th>
802 <th>Description</th>
803 </tr>
804
805 <tr>
806 <td><code>--help</code>
807 </td>
808 <td>Displays command syntax and options</td>
809 </tr>
810
811 <tr>
812 <td style="white-space:nowrap">
813 <code>--size &lt;WIDTHxHEIGHT&gt;</code>
814 </td>
815 <td>Sets the video size: {@code 1280x720}. The default value is the device's native
816 display resolution (if supported), 1280x720 if not. For best results, use a size supported
817 by your device's Advanced Video Coding (AVC) encoder.</td>
818 </tr>
819
820 <tr>
821 <td><code>--bit-rate &lt;RATE&gt;</code></td>
822 <td>Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps.
823 You can increase the bit rate to improve video quality, but doing so results in larger movie
824 files. The following example sets the recording bit rate to 6Mbps:
825 <pre>screenrecord --bit-rate 6000000 &#47;sdcard&#47;demo.mp4</pre>
826 </td>
827 </tr>
828
829 <tr>
830 <td><code>--time-limit &lt;TIME&gt;</code></td>
831 <td>Sets the maximum recording time, in seconds. The default and maximum value is 180
832 (3 minutes).</td>
833 </tr>
834
835 <tr>
836 <td><code>--rotate</code></td>
837 <td>Rotates the output 90 degrees. This feature is experimental.</td>
838 </tr>
839
840 <tr>
841 <td><code>--verbose</code></td>
842 <td>Displays log information on the command-line screen. If you do not set this option,
843 the utility does not display any information while running.</td>
844 </tr>
845
846</table>
847
848
849<h2 id="othershellcommands">Other shell commands</h2>
850
851<p>For a list of all the available shell programs, use the following command:</p>
852
853<pre class="no-pretty-print">adb shell ls /system/bin</pre>
854
855<p>Help is available for most of the commands. </p>
856
857<p>Table 5 lists some of the more common adb shell commands.</p>
858
859<p class="table-caption"><strong>Table 5.</strong> Some other adb shell commands</p>
860<table>
861<tr>
862 <th>Shell Command</th>
863 <th>Description</th>
864 <th>Comments</th>
865</tr>
866
867<tr>
868<td><code>dumpsys</code></td>
869<td>Dumps system data to the screen.</td>
870<td rowspan=4">The <a href="{@docRoot}tools/debugging/ddms.html">Dalvik Debug Monitor Server</a>
David Friedman14dbb902015-09-16 14:33:57 -0700871(DDMS) tool offers an integrated debug environment that you may find easier to use.
872</td>
Luan Nguyen1afb2d52015-01-16 08:21:57 -0800873</tr>
874
875<tr>
876<td><code>dumpstate</code></td>
877<td>Dumps state to a file.</td>
878</tr>
879
880<tr>
881<td><code>logcat&nbsp;[option]...&nbsp;[filter-spec]...</code></td>
882<td>Enables system and app logging and prints output to the screen. </td>
883</tr>
884
885<tr>
886<td><code>dmesg</code></td>
887<td>Prints kernel debugging messages to the screen. </td>
888</tr>
889
890<tr>
891<td><code>start</code></td>
892<td>Starts (restarts) an emulator/device instance.</td>
893<td>&nbsp;</td>
894</tr>
895
896<tr>
897<td><code>stop</code></td>
898<td>Stops execution of an emulator/device instance.</td>
899<td>&nbsp;</td>
900</tr>
901
David Friedman14dbb902015-09-16 14:33:57 -0700902</table>