blob: c339943892b387021bca29c088d2ab89173b8c98 [file] [log] [blame]
Scott Main50e990c2012-06-21 17:14:39 -07001page.title=Android Debug Bridge
2parent.title=Tools
3parent.link=index.html
Joe Fernandez95f6c752013-05-14 16:10:58 -07004page.tags="adb"
Scott Main50e990c2012-06-21 17:14:39 -07005@jd:body
6
7<div id="qv-wrapper">
8<div id="qv">
Scott Main50e990c2012-06-21 17:14:39 -07009 <h2>In this document</h2>
Scott Main7467a0f2013-01-09 18:46:57 -080010<ol>
11 <li><a href="#issuingcommands">Syntax</a></li>
12 <li><a href="#commandsummary">Commands</a></li>
13 <li><a href="#devicestatus">Querying for Emulator/Device Instances</a></li>
14 <li><a href="#directingcommands">Directing Commands to a Specific Emulator/Device Instance</a></li>
15 <li><a href="#move">Installing an Application</a></li>
16 <li><a href="#forwardports">Forwarding Ports</a></li>
17 <li><a href="#copyfiles">Copying Files to or from an Emulator/Device Instance</a></li>
18 <li><a href="#shellcommands">Issuing Shell Commands</a>
19 <ol>
20 <li><a href="#am">Using activity manager (am)</a></li>
21 <li><a href="#pm">Using package manager (pm)</a></li>
22 <li><a href="#sqlite">Examining sqlite3 databases from a remote shell</a></li>
Joe Fernandezfbdd0282013-10-30 18:26:00 -070023 <li><a href="#screenrecord">Recording a device screen</a></li>
Scott Main7467a0f2013-01-09 18:46:57 -080024 <li><a href="#monkey">UI/Application Exerciser Monkey</a></li>
25 <li><a href="#othershellcommands">Other shell commands</a></li>
26 </ol>
27 </li>
28 <li><a href="#logcat">Enabling logcat logging</a></li>
29 <li><a href="#stopping">Stopping the adb server</a></li>
Glenn Kasten77c86262014-02-03 14:01:25 -080030 <li><a href="#wireless">Wireless usage</a></li>
Scott Main7467a0f2013-01-09 18:46:57 -080031</ol>
Scott Main50e990c2012-06-21 17:14:39 -070032
33</div>
34</div>
35
36<p>Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an
37emulator instance or connected Android-powered device. It is a client-server program that includes
38three components: </p>
39
40<ul>
Scott Main7467a0f2013-01-09 18:46:57 -080041 <li>A client, which runs on your development machine. You can invoke a client from a shell
42by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create
43adb clients. </li>
44 <li>A server, which runs as a background process on your development machine. The server
45manages communication between the client and the adb daemon running on an emulator or device. </li>
Scott Main50e990c2012-06-21 17:14:39 -070046 <li>A daemon, which runs as a background process on each emulator or device instance. </li>
47</ul>
48
49<p>You can find the {@code adb} tool in {@code &lt;sdk&gt;/platform-tools/}.</p>
50
Scott Main7467a0f2013-01-09 18:46:57 -080051<p>When you start an adb client, the client first checks whether there is an adb server
52process already running. If there isn't, it starts the server process. When the server starts,
53it binds to local TCP port 5037 and listens for commands sent from adb clients&mdash;all adb
54clients use port 5037 to communicate with the adb server. </p>
Scott Main50e990c2012-06-21 17:14:39 -070055
56<p>The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports &mdash; an even-numbered port for console connections and an odd-numbered port for adb connections. For example: </p>
57
58<p style="margin-left:2em">
59Emulator 1, console: 5554<br/>
60Emulator 1, adb: 5555<br>
61Emulator 2, console: 5556<br>
Scott Main7467a0f2013-01-09 18:46:57 -080062Emulator 2, adb: 5557<br>
63and so on...
Scott Main50e990c2012-06-21 17:14:39 -070064</p>
65
Scott Main7467a0f2013-01-09 18:46:57 -080066<p>As shown, the emulator instance connected to adb on port 5555 is the same as the instance
67whose console listens on port 5554. </p>
Scott Main50e990c2012-06-21 17:14:39 -070068
Scott Main7467a0f2013-01-09 18:46:57 -080069<p>Once the server has set up connections to all emulator instances, you can use adb commands to
70access those instances. Because the server manages connections to emulator/device
71instances and handles commands from multiple adb clients, you can control any emulator/device
72instance from any client (or from a script).</p>
Scott Main50e990c2012-06-21 17:14:39 -070073
Scott Main50e990c2012-06-21 17:14:39 -070074
Scott Main03c54e72013-02-05 14:05:36 -080075<p class="note"><strong>Note:</strong> When you connect a device running Android 4.2.2 or higher
76to your computer, the system shows a dialog asking whether to accept an RSA key that allows
77debugging through this computer. This security mechanism protects user devices because it ensures
78that USB debugging and other adb commands cannot be executed unless you're able to unlock the
79device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with
80SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or
81higher.</p>
Scott Main50e990c2012-06-21 17:14:39 -070082
Scott Main50e990c2012-06-21 17:14:39 -070083
Scott Main7467a0f2013-01-09 18:46:57 -080084<h2 id="issuingcommands">Syntax</h2>
Scott Main50e990c2012-06-21 17:14:39 -070085
Scott Main7467a0f2013-01-09 18:46:57 -080086<p>You can issue adb commands from a command line on your development machine or from a script.
87The usage is: </p>
Scott Main50e990c2012-06-21 17:14:39 -070088
Scott Main7467a0f2013-01-09 18:46:57 -080089<pre class="no-pretty-print">
90adb [-d|-e|-s &lt;serialNumber&gt;] &lt;command&gt;
91</pre>
Scott Main50e990c2012-06-21 17:14:39 -070092
Scott Main7467a0f2013-01-09 18:46:57 -080093<p>If there's only one emulator running or only one device connected, the adb command is
94sent to that device by default. If multiple emulators are running and/or multiple devices are
95attached, you need to use the <code>-d</code>, <code>-e</code>, or <code>-s</code>
96option to specify the target device to which the command should be directed. </p>
Scott Main50e990c2012-06-21 17:14:39 -070097
98
Scott Main50e990c2012-06-21 17:14:39 -070099
Scott Main7467a0f2013-01-09 18:46:57 -0800100<h2 id="commandsummary">Commands</h2>
Scott Main50e990c2012-06-21 17:14:39 -0700101
102<p>The table below lists all of the supported adb commands and explains their meaning and usage. </p>
103
Scott Main7467a0f2013-01-09 18:46:57 -0800104<p class="table-caption"><strong>Table 1.</strong> Available adb commands</p>
Scott Main50e990c2012-06-21 17:14:39 -0700105<table>
106<tr>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700107 <th>Category</th>
108 <th>Command</th>
109 <th>Description</th>
110 <th>Comments</th>
Scott Main50e990c2012-06-21 17:14:39 -0700111</tr>
112
113<tr>
Scott Main7467a0f2013-01-09 18:46:57 -0800114<td rowspan="3">Target Device</td>
Scott Main50e990c2012-06-21 17:14:39 -0700115<td><code>-d</code></td>
116<td>Direct an adb command to the only attached USB device.</td>
117<td>Returns an error if more than one USB device is attached.</td>
118</tr>
119
120<tr>
121<td><code>-e</code></td>
122<td>Direct an adb command to the only running emulator instance.</td>
123<td>Returns an error if more than one emulator instance is running. </td>
124</tr>
125
126<tr>
127<td><code>-s&nbsp;&lt;serialNumber&gt;</code></td>
128<td>Direct an adb command a specific emulator/device instance, referred to by its adb-assigned serial number (such as "emulator-5556").</td>
Scott Main7467a0f2013-01-09 18:46:57 -0800129<td>See <a href="#directingcommands">Directing
130Commands to a Specific Emulator/Device Instance</a>.</td>
Scott Main50e990c2012-06-21 17:14:39 -0700131</tr>
132
133<tr>
134<td rowspan="3">General</td>
135<td><code>devices</code></td>
136<td>Prints a list of all attached emulator/device instances.</td>
137<td>See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information.</td>
138</tr>
139
140<tr>
141<td><code>help</code></td>
142<td>Prints a list of supported adb commands.</td>
143<td>&nbsp;</td>
144</tr>
145
146<tr>
147<td><code>version</code></td>
148<td>Prints the adb version number. </td>
149<td>&nbsp;</td>
150</tr>
151
152<tr>
153<td rowspan="3">Debug</td>
Scott Main7467a0f2013-01-09 18:46:57 -0800154<td ><code>logcat&nbsp;[option] [filter-specs]</code></td>
Scott Main50e990c2012-06-21 17:14:39 -0700155<td>Prints log data to the screen. </td>
156<td>&nbsp;</td>
157</tr>
158
159<tr>
160<td><code>bugreport</code></td>
161<td>Prints <code>dumpsys</code>, <code>dumpstate</code>, and <code>logcat</code> data to the screen, for the purposes of bug reporting. </td>
162<td>&nbsp;</td>
163</tr>
164
165<tr>
166<td><code>jdwp</code></td>
167<td>Prints a list of available JDWP processes on a given device. </td>
168<td>You can use the <code>forward jdwp:&lt;pid&gt;</code> port-forwarding specification to connect to a specific JDWP process. For example: <br>
169 <code>adb forward tcp:8000 jdwp:472</code><br>
170 <code>jdb -attach localhost:8000</code></p>
171 </td>
172</tr>
173
174<tr>
175<td rowspan=3">Data</td>
176<td><code>install&nbsp;&lt;path-to-apk&gt;</code></td>
Scott Main7467a0f2013-01-09 18:46:57 -0800177<td>Pushes an Android application (specified as a full path to an .apk file) to an emulator/device. </td>
Scott Main50e990c2012-06-21 17:14:39 -0700178<td>&nbsp;</td>
179</tr>
180
181<tr>
182<td><code>pull&nbsp;&lt;remote&gt;&nbsp;&lt;local&gt;</code></td>
183<td>Copies a specified file from an emulator/device instance to your development computer. </td>
184<td>&nbsp;</td>
185</tr>
186
187<tr>
188<td><code>push&nbsp;&lt;local&gt;&nbsp;&lt;remote&gt;</code></td>
189<td>Copies a specified file from your development computer to an emulator/device instance. </td>
190<td>&nbsp;</td>
191</tr>
192
193<tr>
194<td rowspan="2">Ports and Networking</td>
195<td><code>forward&nbsp;&lt;local&gt;&nbsp;&lt;remote&gt;</code></td>
196<td>Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance. </td>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700197<td>Port specifications can use these schemes:
Scott Main50e990c2012-06-21 17:14:39 -0700198<ul><li><code>tcp:&lt;portnum&gt;</code></li>
199<li><code>local:&lt;UNIX domain socket name&gt;</code></li>
200<li><code>dev:&lt;character device name&gt;</code></li>
201<li><code>jdwp:&lt;pid&gt;</code></li></ul>
202</td>
203</tr>
204
205<tr>
206<td><code>ppp&nbsp;&lt;tty&gt;&nbsp;[parm]...</code></td>
207<td>Run PPP over USB.
208<ul>
209<li><code>&lt;tty&gt;</code> &mdash; the tty for PPP stream. For example <code>dev:/dev/omap_csmi_ttyl</code>. </li>
210<li><code>[parm]... </code> &mdash; zero or more PPP/PPPD options, such as <code>defaultroute</code>, <code>local</code>, <code>notty</code>, etc.</li></ul>
211
212<p>Note that you should not automatically start a PPP connection. </p></td>
213<td></td>
214</tr>
215
216<tr>
217<td rowspan="3">Scripting</td>
218<td><code>get-serialno</code></td>
219<td>Prints the adb instance serial number string.</td>
220<td rowspan="2">See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information. </td>
221</tr>
222
223<tr>
224<td><code>get-state</code></td>
225<td>Prints the adb state of an emulator/device instance.</td>
226</td>
227</tr>
228
229<tr>
230<td><code>wait-for-device</code></td>
231<td>Blocks execution until the device is online &mdash; that is, until the instance state is <code>device</code>.</td>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700232<td>You can prepend this command to other adb commands, in which case adb will wait until the emulator/device instance is connected before issuing the other commands. Here's an example:
Scott Main7467a0f2013-01-09 18:46:57 -0800233<pre class="no-pretty-print">adb wait-for-device shell getprop</pre>
Scott Main50e990c2012-06-21 17:14:39 -0700234
Joe Fernandez95f6c752013-05-14 16:10:58 -0700235Note that this command does <em>not</em> cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system. As an example, the <code>install</code> requires the Android package manager, which is available only after the system is fully booted. A command such as
Scott Main50e990c2012-06-21 17:14:39 -0700236
Scott Main7467a0f2013-01-09 18:46:57 -0800237<pre class="no-pretty-print">adb wait-for-device install &lt;app&gt;.apk</pre>
Scott Main50e990c2012-06-21 17:14:39 -0700238
239would issue the <code>install</code> command as soon as the emulator or device instance connected to the adb server, but before the Android system was fully booted, so it would result in an error. </td>
240</tr>
241
242
243
244<tr>
245<td rowspan="2">Server</td>
246<td><code>start-server</code></td>
247<td>Checks whether the adb server process is running and starts it, if not.</td>
248<td>&nbsp;</td>
249</tr>
250
251<tr>
252<td><code>kill-server</code></td>
253<td>Terminates the adb server process.</td>
254<td>&nbsp;</td>
255</tr>
256
257
258
259<tr>
260<td rowspan="2">Shell</td>
261<td><code>shell</code></td>
262<td>Starts a remote shell in the target emulator/device instance.</td>
263<td rowspan="2">See <a href="#shellcommands">Issuing Shell Commands</a> for more information. </td>
264</tr>
265
266<tr>
Scott Main7467a0f2013-01-09 18:46:57 -0800267<td><code>shell&nbsp;[shellCommand]</code></td>
Scott Main50e990c2012-06-21 17:14:39 -0700268<td>Issues a shell command in the target emulator/device instance and then exits the remote shell.</td>
269</tr>
270
271</table>
272
273
Scott Main50e990c2012-06-21 17:14:39 -0700274
Scott Main50e990c2012-06-21 17:14:39 -0700275
Scott Main50e990c2012-06-21 17:14:39 -0700276
Scott Main50e990c2012-06-21 17:14:39 -0700277
Scott Main50e990c2012-06-21 17:14:39 -0700278
Scott Main50e990c2012-06-21 17:14:39 -0700279
Scott Main7467a0f2013-01-09 18:46:57 -0800280
281
282<h2 id="devicestatus">Querying for Emulator/Device Instances</h2>
283
284<p>Before issuing adb commands, it is helpful to know what emulator/device instances are connected to the adb server. You can generate a list of attached emulators/devices using the <code>devices</code> command: </p>
285
Joe Fernandez95f6c752013-05-14 16:10:58 -0700286 <pre class="no-pretty-print">adb devices</pre>
Scott Main7467a0f2013-01-09 18:46:57 -0800287
288<p>In response, adb prints this status information for each instance:</p>
289
290<ul>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700291 <li>Serial number &mdash; A string created by adb to uniquely identify an emulator/device instance by its
292 console port number. The format of the serial number is <code>&lt;type&gt;-&lt;consolePort&gt;</code>.
293 Here's an example serial number: <code>emulator-5554</code></li>
294 <li>State &mdash; The connection state of the instance may be one of the following:
295 <ul>
296 <li><code>offline</code> &mdash; the instance is not connected to adb or is not responding.</li>
297 <li><code>device</code> &mdash; the instance is now connected to the adb server. Note that this state does not
298 imply that the Android system is fully booted and operational, since the instance connects to adb
299 while the system is still booting. However, after boot-up, this is the normal operational state of
300 an emulator/device instance.</li>
301 <li><code>no device</code> &mdash; there is no emulator/device connected.
302 </ul>
303 </li>
Scott Main7467a0f2013-01-09 18:46:57 -0800304</ul>
305
306<p>The output for each instance is formatted like this: </p>
307
Joe Fernandez95f6c752013-05-14 16:10:58 -0700308 <pre class="no-pretty-print">[serialNumber] [state]</pre>
Scott Main7467a0f2013-01-09 18:46:57 -0800309
310<p>Here's an example showing the <code>devices</code> command and its output:</p>
311
Joe Fernandez95f6c752013-05-14 16:10:58 -0700312 <pre class="no-pretty-print">adb devices
313List of devices attached
Scott Main7467a0f2013-01-09 18:46:57 -0800314emulator-5554&nbsp;&nbsp;device
315emulator-5556&nbsp;&nbsp;device
316emulator-5558&nbsp;&nbsp;device</pre>
317
318
319
320
321
322
323<h2 id="directingcommands">Directing Commands to a Specific Emulator/Device Instance</h2>
324
325<p>If multiple emulator/device instances are running, you must specify a target instance
326when issuing adb commands. To do so, use the <code>-s</code> option in the commands. The usage
327for the <code>-s</code> option is:</p>
328
Joe Fernandez95f6c752013-05-14 16:10:58 -0700329<pre class="no-pretty-print">adb -s &lt;serialNumber&gt; &lt;command&gt; </pre>
330
Scott Main7467a0f2013-01-09 18:46:57 -0800331<p>As shown, you specify the target instance for a command using its adb-assigned serial number.
332You can use the <code>devices</code> command to obtain the serial numbers of running
333emulator/device instances. For example: </p>
Scott Main50e990c2012-06-21 17:14:39 -0700334
Joe Fernandez95f6c752013-05-14 16:10:58 -0700335<pre class="no-pretty-print">adb -s emulator-5556 install helloWorld.apk</pre>
Scott Main50e990c2012-06-21 17:14:39 -0700336
Scott Main7467a0f2013-01-09 18:46:57 -0800337<p>Note that, if you issue a command without specifying a target emulator/device instance
338while multiple devices are available, adb generates an error.
Scott Main50e990c2012-06-21 17:14:39 -0700339
Scott Main7467a0f2013-01-09 18:46:57 -0800340<p>If you have multiple devices available (hardware or emulated), but only one is an emulator,
341simply use the {@code -e} option to send commands to the emulator. Likewise if there's multiple
342devices but only one hardware device attached, use the {@code -d} option to send commands to
343the hardware device.
Scott Main50e990c2012-06-21 17:14:39 -0700344
Scott Main7467a0f2013-01-09 18:46:57 -0800345
346
347
348<h2 id="move">Installing an Application</h2>
349<p>You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the <code>install</code> command. With the command, you must specify the path to the .apk file that you want to install:</p>
350
351<pre class="no-pretty-print">adb install &lt;path_to_apk&gt;</pre>
352
353<p>For more information about how to create an .apk file that you can install on an emulator/device
354instance, see <a href="{@docRoot}tools/building/index.html">Building and Running</a></p>
355
356<p>Note that, if you are using the Eclipse IDE and have the ADT plugin installed, you do not need to use adb (or aapt) directly to install your application on the emulator/device. Instead, the ADT plugin handles the packaging and installation of the application for you. </p>
357
358
359
360
361
362
363<h2 id="forwardports">Forwarding Ports</h2>
364
365 <p>You can use the <code>forward</code> command to set up arbitrary port forwarding &mdash; forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:</p>
366<pre class="no-pretty-print">adb forward tcp:6100 tcp:7100</pre>
367 <p>You can also use adb to set up forwarding to named abstract UNIX domain sockets, as illustrated here:</p>
368<pre class="no-pretty-print">adb forward tcp:6100 local:logd </pre>
369
370
371
372
373
374<h2 id="copyfiles">Copying Files to or from an Emulator/Device Instance</h2>
375
376<p>You can use the adb commands <code>pull</code> and <code>push</code> to copy files to
377and from an emulator/device instance. Unlike the <code>install</code> command,
378which only copies an APK file to a specific location, the <code>pull</code> and <code>push</code>
379commands let you copy arbitrary directories and files to any location in an
380emulator/device instance. </p>
381
382<p>To copy a file or directory (and its sub-directories) <em>from</em> the emulator or device, use</p>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700383<pre class="no-pretty-print">adb pull &lt;remote&gt; &lt;local&gt;</pre>
Scott Main7467a0f2013-01-09 18:46:57 -0800384
385<p>To copy a file or directory (and its sub-directories) <em>to</em> the emulator or device, use</p>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700386 <pre class="no-pretty-print">adb push &lt;local&gt; &lt;remote&gt;</pre>
Scott Main7467a0f2013-01-09 18:46:57 -0800387
388<p>In the commands, <code>&lt;local&gt;</code> and <code>&lt;remote&gt;</code> refer to the
389paths to the target files/directory on your development machine (local) and on the
390emulator/device instance (remote). For example: </p>
391<pre class="no-pretty-print">adb push foo.txt /sdcard/foo.txt</pre>
392
393
394
395
396
397
398
399
400
401<h2 id="shellcommands">Issuing Shell Commands</h2>
402
Joe Fernandez95f6c752013-05-14 16:10:58 -0700403<p>Adb provides a Unix shell that you can use to run a variety of commands on an emulator
404or connected device. The command binaries are stored in the file system of the emulator or device,
Scott Main7467a0f2013-01-09 18:46:57 -0800405at <code>/system/bin/...</code>
406
407<p>Two of the most common command tools are <a href="#am">activity manager</a> ({@code am}) and
408<a href="#pm">package manager</a> ({@code pm}).</p>
409
410<p>You can use the <code>shell</code> command to issue commands, with or without entering
411the adb remote shell on the emulator/device. To issue a single command without entering a
412remote shell, use the <code>shell</code> command like this: </p>
413
Joe Fernandez95f6c752013-05-14 16:10:58 -0700414 <pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell &lt;shell_command&gt;</pre>
415
Scott Main7467a0f2013-01-09 18:46:57 -0800416<p>Or enter a remote shell on an emulator/device like this:</p>
417
Joe Fernandez95f6c752013-05-14 16:10:58 -0700418 <pre class="no-pretty-print">adb [-d|-e|-s &lt;serialNumber&gt;] shell</pre>
Scott Main7467a0f2013-01-09 18:46:57 -0800419
420<p>When you are ready to exit the remote shell, press CTRL+D or type
421<code>exit</code>. </p>
422
423
424
425
426
427<h3 id="am">Using activity manager (am)</h3>
428
429<p>Within an adb shell, you can issue commands with the activity manager ({@code am}) tool to
430perform various system actions, such as start an activity, force-stop a process,
431broadcast an intent, modify the device screen properties, and more. While in a shell,
432the syntax is:</p>
433<pre class="no-pretty-print">
434am &lt;command>
435</pre>
436
437<p>You can also issue an activity manager command directly from adb
438without entering a remote shell. For example:</p>
439<pre class="no-pretty-print">
440adb shell am start -a android.intent.action.VIEW
441</pre>
442
443
444<p class="table-caption"><strong>Table 2.</strong> Available activity manager commands</p>
445<table>
446<tr>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700447 <th>Command</th>
448 <th>Description</th>
Scott Main7467a0f2013-01-09 18:46:57 -0800449</tr>
450
451<tr>
452<td><code>
453start [options] &lt;INTENT>
454</code></td>
455<td>Start an {@link android.app.Activity} specified by {@code &lt;INTENT>}. <p>See the
456<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
457<p>Options are:
458<ul>
459 <li>{@code -D}: Enable debugging.
460 <li>{@code -W}: Wait for launch to complete.
461 <li>{@code --start-profiler &lt;FILE>}: Start profiler and send results to {@code &lt;FILE>}.
462 <li>{@code -P &lt;FILE>}: Like <code>--start-profiler</code>,
463 but profiling stops when the app goes idle.
464 <li>{@code -R}: Repeat the activity launch {@code &lt;COUNT>} times. Prior to each repeat,
465 the top activity will be finished.
466 <li>{@code -S}: Force stop the target app before starting the activity.
467 <li>{@code --opengl-trace}: Enable tracing of OpenGL functions.
468 <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
469 specified, then run as the current user.
470</ul>
471</td>
472</tr>
473
474<tr>
475<td><code>
476startservice [options] &lt;INTENT>
477</code></td>
478<td>Start the {@link android.app.Service} specified by {@code &lt;INTENT>}. <p>See the
479<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
480<p>Options are:
481<ul>
482 <li>{@code --user &lt;USER_ID> | current}: Specify which user to run as; if not
483 specified, then run as the current user.
484</ul>
485</td>
486</tr>
487
488<tr>
489<td><code>
490force-stop &lt;PACKAGE>
491</code></td>
492<td>Force stop everything associated with {@code &lt;PACKAGE>} (the app's package name).
493</td>
494</tr>
495
496<tr>
497<td><code>
498kill [options] &lt;PACKAGE>
499</code></td>
500<td> Kill all processes associated with {@code &lt;PACKAGE>}
501 (the app's package name). This command kills only
502 processes that are safe to kill and that will not impact the user
503 experience.
504 <p>Options are:
505 <ul>
506 <li>{@code --user &lt;USER_ID> | all | current}: Specify user whose processes to kill;
507 all users if not specified.
508 </ul>
509</td>
510</tr>
511
512<tr>
513<td><code>
514kill-all
515</code></td>
516<td>Kill all background processes.
517</td>
518</tr>
519
520<tr>
521<td><code>
522broadcast [options] &lt;INTENT>
523</code></td>
524<td>Issue a broadcast intent. <p>See the
525<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
526<p>Options are:
527<ul>
528 <li>{@code [--user &lt;USER_ID> | all | current]}: Specify which user to send to; if not
529 specified then send to all users.
530</ul>
531</td>
532</tr>
533
534<tr>
535<td><code>
536instrument [options] &lt;COMPONENT>
537</code></td>
538<td>Start monitoring with an {@link android.app.Instrumentation} instance.
539 Typically the target {@code &lt;COMPONENT>}
540 is the form {@code &lt;TEST_PACKAGE>/&lt;RUNNER_CLASS>}. <p>Options are:
541<ul>
542 <li>{@code -r}: Print raw results (otherwise decode
543 {@code &lt;REPORT_KEY_STREAMRESULT>}). Use with
544 {@code [-e perf true]} to generate raw output for performance measurements.
545
546 <li>{@code -e &lt;NAME> &lt;VALUE>}: Set argument {@code &lt;NAME>} to {@code &lt;VALUE>}.
547 For test runners a common form is {@code
548 -e &lt;testrunner_flag> &lt;value>[,&lt;value>...]}.
549
550 <li>{@code -p &lt;FILE>}: Write profiling data to {@code &lt;FILE>}.
551
552 <li>{@code -w}: Wait for instrumentation to finish before returning. Required for
553 test runners.
554
555 <li>{@code --no-window-animation}: Turn off window animations while running.
556 <li>{@code --user &lt;USER_ID> | current}: Specify which user instrumentation runs in;
557 current user if not specified.
558</ul>
559
560</td>
561</tr>
562
563<tr>
564<td><code>
565profile start &lt;PROCESS> &lt;FILE>
566</code></td>
567<td>Start profiler on {@code &lt;PROCESS>}, write results to {@code &lt;FILE>}.
568</td>
569</tr>
570
571<tr>
572<td><code>
573profile stop &lt;PROCESS>
574</code></td>
575<td>Stop profiler on {@code &lt;PROCESS>}.
576</td>
577</tr>
578
579<tr>
580<td style="white-space:nowrap"><code>
581dumpheap [options] &lt;PROCESS> &lt;FILE>
582</code></td>
583<td>Dump the heap of {@code &lt;PROCESS>}, write to {@code &lt;FILE>}. <p>Options are:
584<ul>
585 <li>{@code --user [&lt;USER_ID>|current]}: When supplying a process name,
586 specify user of process to dump; uses current user if not specified.
587 <li>{@code -n}: Dump native heap instead of managed heap.
588</ul>
589</td>
590</tr>
591
592<tr>
593<td><code>
594set-debug-app [options] &lt;PACKAGE>
595</code></td>
596<td>Set application {@code &lt;PACKAGE>} to debug. <p>Options are:
597<ul>
598 <li>{@code -w}: Wait for debugger when application starts.
599 <li>{@code --persistent}: Retain this value.
600</ul>
601</td>
602</tr>
603
604<tr>
605<td><code>
606clear-debug-app
607</code></td>
608<td>Clear the package previous set for debugging with {@code set-debug-app}.
609</td>
610</tr>
611
612<tr>
613<td><code>
614monitor [options]
615</code></td>
616<td>Start monitoring for crashes or ANRs. <p>Options are:
617<ul>
618 <li>{@code --gdb}: Start gdbserv on the given port at crash/ANR.
619</ul>
620</td>
621</tr>
622
623<tr>
624<td><code>
625screen-compat [on|off] &lt;PACKAGE>
626</code></td>
627<td>Control <a href="{@docRoot}guide/practices/screen-compat-mode.html">screen
628compatibility</a> mode of {@code &lt;PACKAGE>}.</p>
629</td>
630</tr>
631
632<tr>
633<td><code>
634display-size [reset|&lt;WxH>]
635</code></td>
636<td>Override emulator/device display size.
637This command is helpful for testing your app across different screen sizes by mimicking a small
638screen resolution using a device with a large screen, and vice versa.
639<p>Example:<br><code>am display-size 1280x800</code>
640</td>
641</tr>
642
643<tr>
644<td><code>
645display-density &lt;dpi>
646</code></td>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700647<td>Override emulator/device display density.
Scott Main7467a0f2013-01-09 18:46:57 -0800648This command is helpful for testing your app across different screen densities on high-density
649screen environment using a low density screen, and vice versa.
650<p>Example:<br><code>am display-density 480</code>
651</td>
652</tr>
653
654<tr>
655<td><code>
656to-uri &lt;INTENT>
657</code></td>
658<td>Print the given intent specification as a URI. <p>See the
659<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
660</td>
661</tr>
662
663<tr>
664<td><code>
665to-intent-uri &lt;INTENT>
666</code></td>
667<td>Print the given intent specification as an {@code intent:} URI. <p>See the
Joe Fernandez95f6c752013-05-14 16:10:58 -0700668<a href="#IntentSpec">Specification for &lt;INTENT> arguments</a>.
Scott Main7467a0f2013-01-09 18:46:57 -0800669</td>
670</tr>
671</table>
672
673
674
675
676
677<h4 id="IntentSpec">
678 <a href="" class="expandable" onclick="toggleExpandable(this,'.intents');
679return false">Specification for &lt;INTENT> arguments</a></h4>
680
681<div class="intents" style="display:none">
682
683<p>For activity manager commands that take a {@code &lt;INTENT>} argument, you can
684specify the intent with the following options:</p>
685
686<dl>
687 <dt>{@code -a &lt;ACTION>}</dt>
688 <dd>Specify the intent action, such as "android.intent.action.VIEW".
689 You can declare this only once.
690
691 <dt>{@code -d &lt;DATA_URI>}</dt>
692 <dd>Specify the intent data URI, such as "content://contacts/people/1".
693 You can declare this only once.
Joe Fernandez95f6c752013-05-14 16:10:58 -0700694
Scott Main7467a0f2013-01-09 18:46:57 -0800695 <dt>{@code -t &lt;MIME_TYPE>}</dt>
696 <dd>Specify the intent MIME type, such as "image/png".
697 You can declare this only once.
698
699 <dt>{@code -c &lt;CATEGORY>}</dt>
700 <dd>Specify an intent category, such as "android.intent.category.APP_CONTACTS".
701
702 <dt>{@code -n &lt;COMPONENT>}</dt>
Scott Main483d7852013-01-30 15:16:10 -0800703 <dd>Specify the component name with package name prefix to create an explicit intent, such
704 as "com.example.app/.ExampleActivity".
Scott Main7467a0f2013-01-09 18:46:57 -0800705
706 <dt>{@code -f &lt;FLAGS>}</dt>
707 <dd>Add flags to the intent, as supported by {@link
708 android.content.Intent#setFlags setFlags()}.
709
710 <dt>{@code --esn &lt;EXTRA_KEY>}</dt>
711 <dd>Add a null extra. This option is not supported for URI intents.
712
713 <dt>{@code -e|--es &lt;EXTRA_KEY> &lt;EXTRA_STRING_VALUE>}</dt>
714 <dd>Add string data as a key-value pair.
715
716 <dt>{@code --ez &lt;EXTRA_KEY> &lt;EXTRA_BOOLEAN_VALUE>}</dt>
717 <dd>Add boolean data as a key-value pair.
718
719 <dt>{@code --ei &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>}</dt>
720 <dd>Add integer data as a key-value pair.
721
722 <dt>{@code --el &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>}</dt>
723 <dd>Add long data as a key-value pair.
724
725 <dt>{@code --ef &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>}</dt>
726 <dd>Add float data as a key-value pair.
727
728 <dt>{@code --eu &lt;EXTRA_KEY> &lt;EXTRA_URI_VALUE>}</dt>
729 <dd>Add URI data as a key-value pair.
730
731 <dt>{@code --ecn &lt;EXTRA_KEY> &lt;EXTRA_COMPONENT_NAME_VALUE>}</dt>
732 <dd>Add a component name, which is converted and passed as
733 a {@link android.content.ComponentName} object.
734
735 <dt>{@code --eia &lt;EXTRA_KEY> &lt;EXTRA_INT_VALUE>[,&lt;EXTRA_INT_VALUE...]}</dt>
736 <dd>Add an array of integers.
737
738 <dt>{@code --ela &lt;EXTRA_KEY> &lt;EXTRA_LONG_VALUE>[,&lt;EXTRA_LONG_VALUE...]}</dt>
739 <dd>Add an array of longs.
740
741 <dt>{@code --efa &lt;EXTRA_KEY> &lt;EXTRA_FLOAT_VALUE>[,&lt;EXTRA_FLOAT_VALUE...]}</dt>
742 <dd>Add an array of floats.
743
744 <dt>{@code --grant-read-uri-permission}</dt>
745 <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}.
746
747 <dt>{@code --grant-write-uri-permission}</dt>
748 <dd>Include the flag {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}.
749
750 <dt>{@code --debug-log-resolution}</dt>
751 <dd>Include the flag {@link android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION}.
752
753 <dt>{@code --exclude-stopped-packages}</dt>
754 <dd>Include the flag {@link android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES}.
755
756 <dt>{@code --include-stopped-packages}</dt>
757 <dd>Include the flag {@link android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES}.
758
759 <dt>{@code --activity-brought-to-front}</dt>
760 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT}.
761
762 <dt>{@code --activity-clear-top}</dt>
763 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP}.
764
765 <dt>{@code --activity-clear-when-task-reset}</dt>
766 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET}.
767
768 <dt>{@code --activity-exclude-from-recents}</dt>
769 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS}.
770
771 <dt>{@code --activity-launched-from-history}</dt>
772 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY}.
773
774 <dt>{@code --activity-multiple-task}</dt>
775 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}.
776
777 <dt>{@code --activity-no-animation}</dt>
778 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION}.
779
780 <dt>{@code --activity-no-history}</dt>
781 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_HISTORY}.
782
783 <dt>{@code --activity-no-user-action}</dt>
784 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION}.
785
786 <dt>{@code --activity-previous-is-top}</dt>
787 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP}.
788
789 <dt>{@code --activity-reorder-to-front}</dt>
790 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT}.
791
792 <dt>{@code --activity-reset-task-if-needed}</dt>
793 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED}.
794
795 <dt>{@code --activity-single-top}</dt>
796 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP}.
797
798 <dt>{@code --activity-clear-task}</dt>
799 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK}.
800
801 <dt>{@code --activity-task-on-home}</dt>
802 <dd>Include the flag {@link android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME}.
803
804 <dt>{@code --receiver-registered-only}</dt>
805 <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY}.
806
807 <dt>{@code --receiver-replace-pending}</dt>
808 <dd>Include the flag {@link android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING}.
809
810 <dt>{@code --selector}</dt>
811 <dd>Requires the use of {@code -d} and {@code -t} options to set the intent data and type.
812
813 <dt>{@code &lt;URI> &lt;COMPONENT> &lt;PACKAGE>}</dt>
814 <dd>You can directly specify a URI, package name, and component name when not qualified
815 by one of the above options. When an argument is unqualified, the tool assumes the argument
816 is a URI if it contains a ":" (colon); it assumes the argument is a component name if it
817 contains a "/" (forward-slash); otherwise it assumes the argument is a package name.
818
819</dl>
820</div><!-- end 'intents' -->
821<script>
822 $(window).hashchange( function(){
823 if ((location.hash == "#IntentSpec") && !($("#IntentSpec a").hasClass("expanded"))) {
824 $("#IntentSpec a").click();
825 }
826 });
827</script>
828
829
830
831<h3 id="pm">Using package manager (pm)</h3>
832
833<p>Within an adb shell, you can issue commands with the package manager ({@code pm}) tool to
834perform actions and queries on application packages installed on the device. While in a shell,
835the syntax is:</p>
836<pre class="no-pretty-print">
837pm &lt;command>
838</pre>
839
840<p>You can also issue a package manager command directly from adb
841without entering a remote shell. For example:</p>
842<pre class="no-pretty-print">
843adb shell pm uninstall com.example.MyApp
844</pre>
845
846<p class="table-caption"><strong>Table 3.</strong> Available package manager commands.</p>
847<table>
848<tr>
Joe Fernandez95f6c752013-05-14 16:10:58 -0700849 <th>Command</th>
850 <th>Description</th>
Scott Main7467a0f2013-01-09 18:46:57 -0800851</tr>
852
853<tr>
854<td><code>
855list packages [options] &lt;FILTER>
856</code></td>
857<td>Prints all packages, optionally only
858 those whose package name contains the text in {@code &lt;FILTER>}. <p>Options:
859<ul>
860 <li>{@code -f}: See their associated file.
861 <li>{@code -d}: Filter to only show disabled packages.
862 <li>{@code -e}: Filter to only show enabled packages.
863 <li>{@code -s}: Filter to only show system packages.
864 <li>{@code -3}: Filter to only show third party packages.
865 <li>{@code -i}: See the installer for the packages.
866 <li>{@code -u}: Also include uninstalled packages.
867 <li>{@code --user &lt;USER_ID>}: The user space to query.
868</ul>
869</td>
870</tr>
871
872<tr>
873<td><code>
874list permission-groups
875</code></td>
876<td>Prints all known permission groups.
877</td>
878</tr>
879
880<tr>
881<td><code>
882list permissions [options] &lt;GROUP>
883</code></td>
Scott Main03c54e72013-02-05 14:05:36 -0800884<td>Prints all known permissions, optionally only
885 those in {@code &lt;GROUP>}. <p>Options:
886<ul>
887 <li>{@code -g}: Organize by group.
888 <li>{@code -f}: Print all information.
889 <li>{@code -s}: Short summary.
890 <li>{@code -d}: Only list dangerous permissions.
891 <li>{@code -u}: List only the permissions users will see.
Scott Main7467a0f2013-01-09 18:46:57 -0800892</ul>
893</td>
894</tr>
895
896<tr>
897<td><code>
898list instrumentation
899</code></td>
900<td>List all test packages. <p>Options:
Scott Main03c54e72013-02-05 14:05:36 -0800901 <ul>
902 <li>{@code -f}: List the APK file for the test package.
Scott Main7467a0f2013-01-09 18:46:57 -0800903 <li>{@code &lt;TARGET_PACKAGE>}: List test packages for only this app.
904 </ul>
905</td>
906</tr>
907
908<tr>
909<td><code>
910list features
911</code></td>
912<td>Prints all features of the system.
913</td>
914</tr>
915
916<tr>
917<td><code>
918list libraries
919</code></td>
920<td>Prints all the libraries supported by the current device.
921</td>
922</tr>
923
924<tr>
925<td><code>
926list users
927</code></td>
928<td>Prints all users on the system.
929</td>
930</tr>
931
932<tr>
933<td><code>
934path &lt;PACKAGE>
935</code></td>
936<td>Print the path to the APK of the given {@code &lt;PACKAGE>}.
937</td>
938</tr>
939
940<tr>
941<td><code>
942install [options] &lt;PATH>
943</code></td>
944<td>Installs a package (specified by {@code &lt;PATH>}) to the system. <p>Options:
Scott Main03c54e72013-02-05 14:05:36 -0800945 <ul>
946 <li>{@code -l}: Install the package with forward lock.
947 <li>{@code -r}: Reinstall an exisiting app, keeping its data.
948 <li>{@code -t}: Allow test APKs to be installed.
949 <li>{@code -i &lt;INSTALLER_PACKAGE_NAME>}: Specify the installer package name.
950 <li>{@code -s}: Install package on the shared mass storage (such as sdcard).
951 <li>{@code -f}: Install package on the internal system memory.
952 <li>{@code -d}: Allow version code downgrade.
Scott Main7467a0f2013-01-09 18:46:57 -0800953 </ul>
954</td>
955</tr>
956
957<tr>
958<td><code>
959uninstall [options] &lt;PACKAGE>
960</code></td>
961<td>Removes a package from the system. <p>Options:
Scott Main03c54e72013-02-05 14:05:36 -0800962 <ul>
963 <li>{@code -k}: Keep the data and cache directories around after package removal.
Scott Main7467a0f2013-01-09 18:46:57 -0800964 </ul>
965</td>
966</tr>
967
968<tr>
969<td><code>
970clear &lt;PACKAGE>
971</code></td>
972<td>Deletes all data associated with a package.
973</td>
974</tr>
975
976<tr>
977<td><code>
978enable &lt;PACKAGE_OR_COMPONENT>
979</code></td>
980<td>Enable the given package or component (written as "package/class").
981</td>
982</tr>
983
984<tr>
985<td><code>
986disable &lt;PACKAGE_OR_COMPONENT>
987</code></td>
988<td>Disable the given package or component (written as "package/class").
989</td>
990</tr>
991
992<tr>
993<td style="white-space:nowrap"><code>
994disable-user [options] &lt;PACKAGE_OR_COMPONENT>
995</code></td>
996<td><p>Options:
997 <ul>
998 <li>{@code --user &lt;USER_ID>}: The user to disable.
999 </ul>
1000</td>
1001</tr>
1002
1003<tr>
1004<td><code>
1005grant &lt;PACKAGE_PERMISSION>
1006</code></td>
1007<td>Grant permissions
1008 to applications. Only optional permissions the application has
1009 declared can be granted.
1010</td>
1011</tr>
1012
1013<tr>
1014<td><code>
1015revoke &lt;PACKAGE_PERMISSION>
1016</code></td>
1017<td>Revoke permissions
1018 to applications. Only optional permissions the application has
1019 declared can be revoked.
1020</td>
1021</tr>
1022
1023<tr>
1024<td><code>
1025set-install-location &lt;LOCATION>
1026</code></td>
1027<td>Changes the default install location. Location values:
1028<ul>
1029 <li>{@code 0}: Auto&mdash;Let system decide the best location.
1030 <li>{@code 1}: Internal&mdash;install on internal device storage.
1031 <li>{@code 2}: External&mdash;install on external media.
1032</ul>
1033<p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause
1034 applications to break and other undesireable behavior.</p>
1035</td>
1036</tr>
1037
1038<tr>
1039<td><code>
1040get-install-location
1041</code></td>
1042<td>Returns the current install location. Return values:
1043<ul>
1044 <li>{@code 0 [auto]}: Lets system decide the best location
1045 <li>{@code 1 [internal]}: Installs on internal device storage
1046 <li>{@code 2 [external]}: Installs on external media
1047</ul>
1048</td>
1049</tr>
1050
1051<tr>
1052<td><code>
1053set-permission-enforced &lt;PERMISSION> [true|false]
1054</code></td>
1055<td>Specifies whether the given permission should be enforced.
1056</td>
1057</tr>
1058
1059<tr>
1060<td><code>
1061trim-caches &lt;DESIRED_FREE_SPACE>
1062</code></td>
1063<td>Trim cache files to reach the given free space.
1064</td>
1065</tr>
1066
1067<tr>
1068<td><code>
1069create-user &lt;USER_NAME>
1070</code></td>
1071<td>Create a new user with the given {@code &lt;USER_NAME>},
1072 printing the new user identifier of the user.
1073</td>
1074</tr>
1075
1076<tr>
1077<td><code>
1078remove-user &lt;USER_ID>
1079</code></td>
1080<td>Remove the user with the given {@code &lt;USER_IDENTIFIER>},
1081 deleting all data associated with that user
1082</td>
1083</tr>
1084
1085<tr>
1086<td><code>
1087get-max-users
1088</code></td>
1089<td>Prints the maximum number of users supported by the device.
1090</td>
1091</tr>
1092
1093</table>
1094
1095
1096
1097
1098
1099
1100
1101<h3 id="sqlite">Examining sqlite3 databases from a remote shell</h3>
Scott Main50e990c2012-06-21 17:14:39 -07001102
Joe Fernandez95f6c752013-05-14 16:10:58 -07001103<p>From an adb remote shell, you can use the
1104<a href="http://www.sqlite.org/sqlite.html">sqlite3</a> command-line program to
1105manage SQLite databases created by Android applications. The
1106<code>sqlite3</code> tool includes many useful commands, such as
1107<code>.dump</code> to print out the contents of a table and
1108<code>.schema</code> to print the SQL CREATE statement for an existing table.
Scott Main50e990c2012-06-21 17:14:39 -07001109The tool also gives you the ability to execute SQLite commands on the fly.</p>
1110
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001111<p>To use <code>sqlite3</code>, enter a remote shell on the emulator instance, as described above,
1112then invoke the tool using the <code>sqlite3</code> command. Optionally, when invoking
1113<code>sqlite3</code> you can specify the full path to the database you want to explore.
1114Emulator/device instances store SQLite3 databases in the folder
1115<code><span chatdir="1"><span chatindex="259474B4B070F261">/data/data/<em>&lt;package_name&gt;</em>/databases</span></span>/</code>. </p>
Scott Main50e990c2012-06-21 17:14:39 -07001116
1117<p>Here's an example: </p>
1118
Scott Main7467a0f2013-01-09 18:46:57 -08001119<pre class="no-pretty-print">adb -s emulator-5554 shell
Scott Main50e990c2012-06-21 17:14:39 -07001120# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
1121SQLite version 3.3.12
1122Enter &quot;.help&quot; for instructions
1123<em>.... enter commands, then quit...</em>
1124sqlite&gt; .exit </pre>
1125
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001126<p>Once you've invoked <code>sqlite3</code>, you can issue <code>sqlite3</code> commands in the
1127shell. To exit and return to the adb remote shell, use <code>exit</code> or <code>CTRL+D</code>.
Scott Main50e990c2012-06-21 17:14:39 -07001128
1129
Scott Main50e990c2012-06-21 17:14:39 -07001130
Scott Main7467a0f2013-01-09 18:46:57 -08001131
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001132<h3 id="screenrecord">Recording a device screen</h3>
1133
Joe Fernandez156cc152013-10-31 13:58:11 -07001134<p>The {@code screenrecord} command is a shell utility for recording the display of devices
1135 running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4
1136 file, which you can then download and use as part of a video presentation. This utility is useful
1137 for developers who want to create promotional or training videos without using a separate
1138 recording device.</p>
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001139
1140<p>To use the {@code screenrecord} from the command line, type the following:
1141
1142<pre>
1143$ adb shell screenrecord /sdcard/demo.mp4
1144</pre>
1145
1146<p>Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically
1147at three minutes or the time limit set by {@code --time-limit}.</p>
1148
1149<p>Here's an example recording session, using the adb shell to record the video and the
1150{@code pull} command to download the file from the device:<p>
1151
1152<pre>
1153$ adb shell
1154shell@ $ screenrecord --verbose /sdcard/demo.mp4
1155(press Ctrl-C to stop)
1156shell@ $ exit
1157$ adb pull /sdcard/demo.mp4
1158</pre>
1159
1160<p>The {@code screenrecord} utility can record at any supported resolution and bit rate you
1161 request, while retaining the aspect ratio of the device display. The utility records at the native
1162 display resolution and orientation by default, with a maximum length of three minutes.</p>
1163
1164<p>There are some known limitations of the {@code screenrecord} utility that you should be aware
1165 of when using it:</p>
1166
1167<ul>
1168 <li>Some devices may not be able to record at their native display resolution.
1169 If you encounter problems with screen recording, try using a lower screen resolution.</li>
1170 <li>Rotation of the screen during recording is not supported. If the screen does rotate during
1171 recording, some of the screen is cut off in the recording.</li>
1172 <li>Audio is not recorded with the video file.</li>
1173</ul>
1174
1175
1176<p class="table-caption"><strong>Table 4.</strong> {@code screenrecord} options</p>
1177
1178<table>
1179 <tr>
1180 <th>Options</th>
1181 <th>Description</th>
1182 </tr>
1183
1184 <tr>
1185 <td><code>--help</code>
1186 </td>
1187 <td>Displays a usage summary.</td>
1188 </tr>
1189
1190 <tr>
1191 <td style="white-space:nowrap">
1192 <code>--size &lt;WIDTHxHEIGHT&gt;</code>
1193 </td>
1194 <td>Sets the video size, for example: {@code 1280x720}. The default value is the device's main
1195 display resolution (if supported), 1280x720 if not. For best results, use a size supported
1196 by your device's Advanced Video Coding (AVC) encoder.</td>
1197 </tr>
1198
1199 <tr>
1200 <td><code>--bit-rate &lt;RATE&gt;</code></td>
1201 <td>Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps.
1202 You can increase the bit rate to improve video quality or lower it for smaller movie
1203 files. The following example sets the recording bit rate to 6Mbps:
1204 <pre>screenrecord --bit-rate 6000000 &#47;sdcard&#47;demo.mp4</pre>
1205 </td>
1206 </tr>
1207
1208 <tr>
1209 <td><code>--time-limit &lt;TIME&gt;</code></td>
1210 <td>Sets the maximum recording time, in seconds. The default and maximum value is 180
1211 (3 minutes).</td>
1212 </tr>
1213
1214 <tr>
1215 <td><code>--rotate</code></td>
1216 <td>Rotates the output 90 degrees. This feature is experimental.</td>
1217 </tr>
1218
1219 <tr>
1220 <td><code>--verbose</code></td>
1221 <td>Displays log information on command line screen. If you do not set this option,
1222 the utility does not display any information while running.</td>
1223 </tr>
1224
1225</table>
1226
1227
Scott Main7467a0f2013-01-09 18:46:57 -08001228
1229
1230<h3 id="monkey">UI/Application Exerciser Monkey</h3>
Scott Main50e990c2012-06-21 17:14:39 -07001231
1232<p>The Monkey is a program that runs on your emulator or device and generates pseudo-random
Joe Fernandez95f6c752013-05-14 16:10:58 -07001233streams of user events such as clicks, touches, or gestures, as well as a number of system-level
Scott Main50e990c2012-06-21 17:14:39 -07001234events. You can use the Monkey to stress-test applications that you are developing,
1235in a random yet repeatable manner.</p>
1236
Scott Main7467a0f2013-01-09 18:46:57 -08001237<p>The simplest way to use the monkey is with the following command, which launches your
1238application and sends 500 pseudo-random events to it.</p>
Scott Main50e990c2012-06-21 17:14:39 -07001239
Scott Main7467a0f2013-01-09 18:46:57 -08001240<pre class="no-pretty-print">adb shell monkey -v -p your.package.name 500</pre>
Scott Main50e990c2012-06-21 17:14:39 -07001241
Joe Fernandez95f6c752013-05-14 16:10:58 -07001242<p>For more information about command options for Monkey, see the complete
Scott Main50e990c2012-06-21 17:14:39 -07001243<a href="{@docRoot}tools/help/monkey.html" title="monkey">UI/Application Exerciser Monkey</a> documentation page.</p>
1244
1245
Scott Main50e990c2012-06-21 17:14:39 -07001246
Scott Main50e990c2012-06-21 17:14:39 -07001247
Scott Main50e990c2012-06-21 17:14:39 -07001248
Scott Main7467a0f2013-01-09 18:46:57 -08001249<h3 id="othershellcommands">Other shell commands</h3>
1250
1251<p>For a list of all the available shell programs, use the following command:</p>
1252
1253<pre class="no-pretty-print">adb shell ls /system/bin</pre>
Scott Main50e990c2012-06-21 17:14:39 -07001254
1255<p>Help is available for most of the commands. </p>
1256
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001257<p>Table 5 lists some of the more common adb shell commands.</p>
Scott Main7467a0f2013-01-09 18:46:57 -08001258
Joe Fernandezfbdd0282013-10-30 18:26:00 -07001259<p class="table-caption"><strong>Table 5.</strong> Some other adb shell commands</p>
Scott Main50e990c2012-06-21 17:14:39 -07001260<table>
1261<tr>
Joe Fernandez95f6c752013-05-14 16:10:58 -07001262 <th>Shell Command</th>
1263 <th>Description</th>
1264 <th>Comments</th>
Scott Main50e990c2012-06-21 17:14:39 -07001265</tr>
1266
1267<tr>
1268<td><code>dumpsys</code></td>
1269<td>Dumps system data to the screen.</td>
Joe Fernandez95f6c752013-05-14 16:10:58 -07001270<td rowspan=4">The <a href="{@docRoot}tools/debugging/ddms.html">Dalvik Debug Monitor Server</a>
Scott Main50e990c2012-06-21 17:14:39 -07001271(DDMS) tool offers integrated debug environment that you may find easier to use.</td>
1272</tr>
1273
1274<tr>
1275<td><code>dumpstate</code></td>
1276<td>Dumps state to a file.</td>
1277</tr>
1278
1279<tr>
Scott Main7467a0f2013-01-09 18:46:57 -08001280<td><code>logcat&nbsp;[option]...&nbsp;[filter-spec]...</code></td>
1281<td>Enables system and app logging and prints output to the screen. </td>
Scott Main50e990c2012-06-21 17:14:39 -07001282</tr>
1283
1284<tr>
1285<td><code>dmesg</code></td>
1286<td>Prints kernel debugging messages to the screen. </td>
1287</tr>
1288
1289<tr>
1290<td><code>start</code></td>
1291<td>Starts (restarts) an emulator/device instance.</td>
1292<td>&nbsp;</td>
1293</tr>
1294
1295<tr>
1296<td><code>stop</code></td>
1297<td>Stops execution of an emulator/device instance.</td>
1298<td>&nbsp;</td>
1299</tr>
1300
1301</table>
Scott Main7467a0f2013-01-09 18:46:57 -08001302
1303
1304
1305
1306
1307
1308
Dirk Doughertyfe57f382012-06-28 15:35:12 -07001309<a name="stdout"></a>
1310<a name="usinglogcat"></a>
1311<a name="outputformat"></a>
1312<a name="filteringoutput"></a>
1313<a name="stdout"></a>
1314<a name="logcatoptions"></a>
Scott Main50e990c2012-06-21 17:14:39 -07001315
Scott Main7467a0f2013-01-09 18:46:57 -08001316<h2 id="logcat">Enabling logcat logging</h2>
Scott Main50e990c2012-06-21 17:14:39 -07001317
1318<p>The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the <code>logcat</code> command.</p>
1319
Scott Main50e990c2012-06-21 17:14:39 -07001320<p>You can use the <code>logcat</code> command to view and follow the contents of the system's log buffers. The general usage is:</p>
1321
Scott Main7467a0f2013-01-09 18:46:57 -08001322<pre class="no-pretty-print">[adb] logcat [option] ... [filter-spec] ...</pre>
Scott Main50e990c2012-06-21 17:14:39 -07001323
Scott Main50e990c2012-06-21 17:14:39 -07001324<p>You can use the <code>logcat</code> command from your development computer or from a remote adb shell in an emulator/device instance. To view log output in your development computer, you use</p>
1325
Scott Main7467a0f2013-01-09 18:46:57 -08001326<pre class="no-pretty-print">adb logcat</pre>
Scott Main50e990c2012-06-21 17:14:39 -07001327
1328<p>and from a remote adb shell you use</p>
1329
Scott Main7467a0f2013-01-09 18:46:57 -08001330<pre class="no-pretty-print">logcat</pre>
Scott Main50e990c2012-06-21 17:14:39 -07001331
Dirk Doughertyfe57f382012-06-28 15:35:12 -07001332<p>See <a href="{@docRoot}tools/debugging/debugging-log.html">Reading and Writing Logs</a> for complete information about logcat commend options and filter specifications.</p>
Scott Main50e990c2012-06-21 17:14:39 -07001333
Scott Main50e990c2012-06-21 17:14:39 -07001334
Scott Main50e990c2012-06-21 17:14:39 -07001335
Scott Main7467a0f2013-01-09 18:46:57 -08001336
1337
1338<h2 id="stopping">Stopping the adb server</h2>
Scott Main50e990c2012-06-21 17:14:39 -07001339
1340<p>In some cases, you might need to terminate the adb server process and then restart it. For example, if adb does not respond to a command, you can terminate the server and restart it and that may resolve the problem. </p>
1341
Scott Main7467a0f2013-01-09 18:46:57 -08001342<p>To stop the adb server, use the <code>kill-server</code> command.
1343You can then restart the server by issuing any other adb command. </p>
Scott Main50e990c2012-06-21 17:14:39 -07001344
1345
Glenn Kasten77c86262014-02-03 14:01:25 -08001346<h2 id="wireless">Wireless usage</h2>
1347
1348<p>
1349adb is usually used over USB. However, it is also possible to use over
1350Wi-Fi, as described here.
1351</p>
1352
1353<ol>
1354
1355<li>
1356Connect Android device and adb host computer
1357to a common Wi-Fi network accessible to both.
1358We have found that not all access points
1359are suitable; you may need to use an access point
1360whose firewall is configured properly to support adb.
1361</li>
1362
1363<li>
1364Connect the device with USB cable to host.
1365</li>
1366
1367<li>
1368Make sure adb is running in USB mode on host.
1369<pre>
1370$ adb usb
1371restarting in USB mode
1372</pre>
1373</li>
1374
1375<li>
1376Connect to the device over USB.
1377<pre>
1378$ adb devices
1379List of devices attached
1380######## device
1381</pre>
1382</li>
1383
1384<li>
1385Restart host adb in tcpip mode.
1386<pre>
1387$ adb tcpip 5555
1388restarting in TCP mode port: 5555
1389</pre>
1390</li>
1391
1392<li>
1393Find out the IP address of the Android device:
1394Settings -> About tablet -> Status -> IP address.
1395Remember the IP address, of the form <code>#.#.#.#</code>.
1396</li>
1397
1398<li>
1399Connect adb host to device:
1400<pre>
1401$ adb connect #.#.#.#
1402connected to #.#.#.#:5555
1403</pre>
1404</li>
1405
1406<li>
1407Remove USB cable from device, and confirm you can still access device:
1408<pre>
1409$ adb devices
1410List of devices attached
1411#.#.#.#:5555 device
1412</pre>
1413
1414</ol>
1415
1416<p>
1417You're now good to go!
1418</p>
1419
1420<p>
1421If the adb connection is ever lost:
1422</p>
1423
1424<ol>
1425
1426<li>
1427Make sure that your host is still connected to the same Wi-Fi network your Android device is.
1428</li>
1429
1430<li>
1431Reconnect by executing the "adb connect" step again.
1432</li>
1433
1434<li>
1435Or if that doesn't work, reset your adb host:
1436<pre>
1437adb kill-server
1438</pre>
1439and then start over from the beginning.
1440</li>
1441
1442</ol>