└── ADB.md /ADB.md: -------------------------------------------------------------------------------- 1 | #### View connected device 2 | 3 | ```sh 4 | $ adb devices 5 | ``` 6 | 7 | If multiple devices are attached, use `adb -s DEVICE_ID` to target a specific device 8 | 9 | 10 | #### List of running services 11 | 12 | ```sh 13 | $ adb shell dumpsys activity services 14 | ``` 15 | 16 | #### Install an app in the connected device 17 | 18 | ```sh 19 | $ adb -s xxx.xxx.xx.xxx:5555 install Downloads/com.xxx.android.2.8.0.apk 20 | ``` 21 | 22 | #### Update an app in the connected device 23 | 24 | ```sh 25 | $ adb -s xxx.xxx.xx.xxx:5555 install -r Downloads/com.xxx.android.2.8.0.apk 26 | ``` 27 | *the optional -r argument reinstalls and keeps any data if the application is already installed on the device. It is helpful in updating the app from current Build(1.0) to next Build(1.1)* 28 | 29 | #### Copy file to the connected device 30 | 31 | ```sh 32 | $ adb push Downloads/test-copy.rtf /sdcard/test-copy.txt 33 | ``` 34 | 35 | #### Fetch file from connected device 36 | 37 | ```sh 38 | $ adb pull /sdcard/foo.txt Downloads/acd.txt 39 | ``` 40 | 41 | #### Start a remote shell 42 | 43 | ```sh 44 | $ adb -s xxx.xxx.xx.xxx:5555 shell 45 | ``` 46 | 47 | #### Issuing single command without entering remote shell 48 | 49 | ```sh 50 | $ adb shell ls /system/bin 51 | ``` 52 | 53 | #### Issuing monkey command 54 | 55 | ```sh 56 | $ adb shell monkey -v -p com.xxxx.android 400 57 | ``` 58 | 59 | *Monkey is a program that runs on your emulator/device and generates random streams of user events such as clicks, touches, or gestures in the app.* 60 | 61 | #### View log of system messages 62 | 63 | ```sh 64 | $ adb logcat 65 | ``` 66 | 67 | ####Wireless usage 68 | 69 | adb is usually used over USB. However, it is also possible to use over Wi-Fi, as described here. 70 | 71 | 1. Connect your Android device and adb host computer to a common Wi-Fi network accessible to both. We have found that not all access points are suitable; you may need to use an access point whose firewall is configured properly to support adb.
Note: If you are attempting to connect to a Wear device, force it to connect to Wi-Fi by shutting off Bluetooth on the phone connected to it. 72 | 73 | 74 | 2. Connect the device to the host computer with a USB cable. 75 | 76 | 77 | 3. Set the target device to listen for a TCP/IP connection on port 5555. 78 | $ adb tcpip 5555 79 | 80 | 81 | 4. Disconnect the USB cable from the target device. 82 | 83 | 84 | 5. Find the IP address of the Android device. For example, on a Nexus device, you can find the IP address at Settings > About tablet (or About phone) > Status > IP address. Or, on an Android Wear device, you can find the IP address at Settings > Wi-Fi Settings > Advanced > IP address. 85 | 86 | 87 | 88 | 6. Connect to the device, identifying it by IP address. 89 | $ adb connect 90 | 91 | 92 | 7. Confirm that your host computer is connected to the target device: $ adb devices 93 | List of devices attached 94 | :5555 device 95 | 96 | #### Filter by tagname in Logcat 97 | 98 | ```sh 99 | $ adb logcat -s TAG_NAME 100 | $ adb logcat -s TAG_NAME_1 TAG_NAME_2 101 | ``` 102 | 103 | #### Filter by priority in Logcat 104 | 105 | ```sh 106 | $ adb logcat "*:" 107 | # Where can be V (Verbose), D (Debug), I (Info), W (Warning), E (Error), F (Fatal), S (Silent). 108 | ``` 109 | 110 | It can be combined with tagname command, to filter by tagname and priority 111 | ```sh 112 | $ adb logcat -s TEST: W 113 | ``` 114 | 115 | #### Filter using grep in Logcat 116 | 117 | ```sh 118 | $ adb logcat | grep "term" 119 | $ adb logcat | grep "term1\|term2" 120 | ``` 121 | 122 | #### Find out processor version on Android Device (check if it's an ARM, for example) 123 | 124 | ```sh 125 | $ adb shell cat /proc/cpuinfo 126 | ``` 127 | 128 | #### Unlock screen 129 | 130 | ```sh 131 | $ adb -s DEVICE_ID shell input keyevent 82 132 | ``` 133 | #### Use Power screen 134 | 135 | ```sh 136 | $ adb -s DEVICE_ID shell input keyevent 26 137 | ``` 138 | 139 | #### View all installed packages 140 | 141 | ```sh 142 | $ adb -s DEVICE_ID shell pm list packages -f 143 | ``` 144 | 145 | #### Start an activity 146 | 147 | ```sh 148 | $ adb -s DEVICE_ID shell am start PACKAGE_NAME/ACTIVITY_IN_PACKAGE 149 | $ adb -s DEVICE_ID shell am start PACKAGE_NAME/FULLY_QUALIFIED_ACTIVITY 150 | 151 | Examples: 152 | adb -s 192.168.56.101:5555 shell am start -n com.xxxx.android/.activities.MainActivity 153 | 154 | adb -s 192.168.56.101:5555 shell am start -n com.xxxx.android/com.xxxx.android.activities.MainActivity 155 | ``` 156 | 157 | 158 | #### Launch default browser at a URL 159 | 160 | ```sh 161 | $ adb -s DEVICE_ID shell am start -a android.intent.action.VIEW -d http://www.google.com 162 | ``` 163 | 164 | #### Taking screenshot 165 | 166 | ```sh 167 | $ adb -s DEVICE_ID shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png 168 | ``` 169 | *Screenshot will be stored in you client machine from where you have executed the command. Look into the same directory from where you have executed the command.* 170 | 171 | ### Screen record 172 | ```sh 173 | $ screenrecord [options] 174 | 175 | Examples : 176 | $adb shell screenrecord /sdcard/demo.mp4 177 | ``` 178 | *Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically at three minutes or the time limit set by --time-limit. 179 | To begin recording your device screen, run the screenrecord command to record the video. Then, run the pull command to download the video from the device to the host computer.* --------------------------------------------------------------------------------