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