8 Things You Didn’t Know You Could Do with ADB
ADB is a debugging tool for developers in Android. A developer can use it to perform several programming activities and check the system's behavior when the app is in operation. There are a few ADB commands that can be useful and help you make yourself more productive, and save your time even if you are just average or a non-developer. Here are some cool tricks that you can do with ADB.
#1 Create a Full Backup of Your Phone
The Android recovery mode helps you to set up backups and reset your phone. These backups can be kept on a phone or SD card only, however. A full backup of your phone on a computer can be created with the help of ADB.
Enter the following command to create a complete phone backup.
adb backup -all -f /backup/location/file.ab
This command secures all applications and their data on your file location. Make sure you add the “.ab” file extension to the filename.
After you have entered, your phone has to be unlocked and the data has to be saved. A password to encrypt the data can also be entered. When restored the data, the password is used.
Other options you can add:
- -apk : This will back up .apk files
- -noapk : Will not back up .apk files
- -obb: Will back up .obb files
- -shared: Will back up SD card data
- -noshared: Will not back up SD card data
- -nosystem: Will not back up system apps when -all is added.
Enter the following command to restore the backup on your mobile:
adb restore < backup-file-location >
Unlock your phone and enter the password to restore the backup on your phone.
#2 Backup a Specific App and Its Data
ADB can also assist you in saving only a certain application and its data. This can help if you want to play a game with the previously saved gameplay on a different phone. It also saves the app's cache so it can be useful for apps such as YouTube that cache offline videos.
To back up the app, the package name of the app first has to be known. Use the following command to find the package name.
adb shell pm list packages
The package names on your phone will be listed. Select and copy the name of the application package you wish to backup.
Enter the following command to back up the app and its data:
adb backup -f < file-location-for-backup> -apk < package-name >
Replace < package-name > with the previously copied package name and also add a file location as added in the previous section. Hit Enter. You will be asked to permit the execution of the backup command on your phone just like the previous section.
To restore the app, enter the following command:
adb restore < backup-file-location >
#3 Install Multiple Apps
You can easily batch the installation of multiple applications (apk files) on your phone using ADB if they are stored in a folder. One thing to note is that your phone will not receive any prompt screen, so be vigilant when you install the apps. Make sure they don’t contain malware (or a malware app).
Enter the following command to install multiple apps from a folder:
for %f in (< folder-path >\*.apk) do adb install "%f"
You will get a “Success” message after each app installation.
#4 Extract APK from Your Phone
For some reason, ADB can easily extract the app's apk from your phone.
First, the package name of the app you'll extract must be known. Run the command list package displayed in the second section to receive the package name.
adb shell pm list packages
You have to get this package's path or file location. This path will be used to extract the phone's APK.
adb shell pm path < package-name >
Copy the path and paste it in the below given command:
adb pull < package-location > < path-on-computer-to-store-APK >
This will store “base.apk” (which is the APK of the file selected by you) on your computer. You can rename it later.
#5 Record Screen
Many apps have been developed in the Play Store, but it is always cool to do with ADB. In addition, this saves your phone storage space as no additional application for the job needs to be installed.
Enter the following command to start recording the screen on your phone:
adb shell screenrecord < folder-path/filename.mp4 >
Your phone storage or SD card should be included in the command above. There is also a small limitation here – the display is recorded by ADB for a maximum of 3 minutes. You can also add a parameter -time-limit < number of seconds > to set the time limit beforehand. If you want to stop recording, then you can click on "Ctrl+C."
#6 Change DPI of the Screen
DPI is a value used by Android for determining the optimal image and app icon size to be displayed on the display. You can modify this value to have a larger, zoom-in or smaller display as required. Please check the images below. The left image is 480 dpi, while the right image is 180 dpi.
To check what the current dpi is on your phone, enter the following command:
adb shell wm density
To change the dpi, just add the value next to it.
adb shell wm density < value >
You can see the change live on the screen, and no reboot is required. You can switch back to original dpi using the same command.
#7 Connect ADB Over WiFi
Why not connect wirelessly to adb in today's world, where everything goes wireless? This is pretty easy to do. In order to enable your phone, however, you must first connect via USB. In addition, turn your phone and computer on WiFi and make your phone on the same wireless network.
Enter the following command to make ADB run in TCP/IP mode:
adb tcpip 5555
Get the IP address of your phone from “Settings -> About -> Status -> IP address” and enter it in the next command.
Enter the command to wirelessly connect ADB with your phone.
adb connect < your-ip-address >
You can now disconnect your USB cable.
Enter the following command to check if it’s connected wirelessly:
#8 Get System Stats and Info
There is a shell command called dumpsys which developers use when their app is running to check system behaviour. This command can be used to obtain further information about the phone system and to verify your knowledge from various other hardware informations.
Enter the following command to get all the sub-commands that can be used with dumpsys.
adb shell dumpsys | grep "DUMP OF SERVICE"
Now, use the sub-commands accordingly with dumpsys to get more information about various hardware on your phone. The following command shows battery information.
adb shell dumpsys battery