Wednesday, January 10, 2018

8 Things You Didn’t Know You Could Do with ADB

https://www.maketecheasier.com/things-you-could-do-with-adb

ADB (Android Debug Bridge) is a debugging tool for Android developers. A developer can use it to perform many programming actions and can check the behavior of the system when the app is running. Even if you are just an average user or a non-developer, there are a few ADB commands that can be useful and help you to be more productive and save you time. Here are some cool tricks that you can do with ADB.
The Recovery mode in Android helps you to reset your phone and create backups. However, these backups can only be stored on phone storage or SD card. With the help of ADB, you can create a full backup of your phone on your computer.
Enter the following command to create a full backup of your phone.
adb backup -all -f /backup/location/file.ab
adb-full-backup-2
The above command will back up all the apps and its data at the file location provided by you. Make sure you add the “.ab” file extension to the filename.
After you hit Enter, you will have to unlock your phone and give permission to back up the data. You can also enter a password to encrypt the data. The password will be used when restoring the data.
adb-backup-permission
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
  • -noobb: Will not 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.
To restore the backup on your phone enter the following command:
adb restore <backup-file-location>
adb-full-backup-restore
Unlock your phone and enter the password to restore the backup on your phone.
If you want to back up only a specific app and its data, ADB can help you with that, too. This can be helpful in cases where you want to play a game on a different phone with your previously saved gameplay. Also, it stores the cache of the app so it can be useful for apps like YouTube that save the offline videos as cached files.
In order to back up the app, you need to first know the package name of the app. You can find the package name using the following command.
adb shell pm list packages
This will list all the package names installed on your phone. Find the name of the app package that you want to back up and copy it.
Enter the following command to back up the app and its data:
adb backup -f <file-location-for-backup> -apk <package-name>
adb-app-backup
Replace 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>
If you have multiple apps (apk files) stored in a folder, you can easily batch install them on your phone using ADB. One thing to note is that you won’t get any prompt screen on your phone, so be careful with the apps you are going to install. 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"
adb-install-multiple-apps
You will get a “Success” message after each app installation.
For some reason if you require the apk of an app from your phone, ADB can easily extract it for you.
First, you need to know the package name of the app that you are going to extract. Perform the list package command shown in the 2nd section to get the package name.
adb shell pm list packages
You need to get the path or file location of this package. We’ll use this path to extract the APK from the phone.
adb shell pm path <package-name>
adb-get-apk-path
Copy the path and paste it in the below given command:
adb pull <package-location> <path-on-computer-to-store-APK>
adb-extract-apk
This will store “base.apk” (which is the APK of the file selected by you) on your computer. You can rename it later.
There are many apps available on the Play Store for this, but doing it with ADB is always cool. Also, this will save storage space on your phone as you won’t have to install another app for the task.
Enter the following command to start recording the screen on your phone:
adb shell screenrecord <folder-path/filename.mp4>
adb-screenrecord
The path to be added in the above command should be of your phone storage or SD card. Also, there’s a slight limitation here – ADB will record the screen for 3 minutes maximum. If you want to stop the recording in between, you can press “Ctrl + C.” Apart from that, you can add parameter -time-limit to set the time limit beforehand.
DPI (Dots per Inch) is a value that Android uses to determine the ideal size of images and app icons to show on the screen. This value can be changed to get a larger, zoomed-in display or smaller display as per your needs. Check the below screenshots. The left image is at normal 480 dpi, and the right one is at 180dpi.
adb-change-dpi-example
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>
adb-change-dpi
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.
In today’s world where everything is going wireless, why not connect to adb wirelessly too? It’s quite easy to make this happen. However, you’ll first need to connect your phone via USB to enable it. Also, turn on WiFi on your phone and your computer, and your phone should be 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:
adb devices
adb-wireless-connection
There is a shell command called dumpsys that developers use to check the system behavior when their app is running. You can use this command to get more info about the phone’s system and check various other hardware info for your knowledge.
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
adb-dumpsys
Play around with other sub-commands and get more info about the phone hardware and its status.
There are plenty of things that you can do with ADB, and you don’t need to be a developer to tinker with it. You can also check out this page for all other ADB commands. ADB can be even more useful if you have rooted your phone. Root access will open a plethora of tricks that you can do with ADB on your phone.
If you come up with an error or have any issues using ADB, let us know in the comments below.

No comments:

Post a Comment