Useful ADB commands for better Android Development

Shahzar Ahmed
2 min readSep 29, 2020

--

ADB shell commands can be of great help when developing Android Applications. You might have already heard of adb install & adb uninstall commands, for installing and uninstalling applications respectively.

I’ll be listing out few more commands which helped me ease the development pain.

1) Access app data of your debug-able application (no-root)

Generally, when developing an application we would like to access the internal app data to get hold of the app’s private data such as Shared Preference or the SQLite database for manual inspection.

adb shell run-as com.example.app

The above command grants the shell the application’s permissions. You can now access all the private app data most commonly located at /data/data/com.example.app

2) Simulate process death

Process death can happen when Android decides to kill off applications running in the background, when the device is running low on memory, to provide memory for applications running in the foreground.

Although this is unlikely to happen considering the large enough memory devices nowadays come with, certain OEMs tweak the Android OS to be aggressive in killing off applications in the background, to conserve battery. Hence it is a good practice to handle these scenarios when developing applications.

Process death can be simulated by using the following commands.

// Only kills safe-to-kill processesadb shell am kill <package-name> 
// Kills the whole process of your application
adb shell kill <package-name>

3) Capture & import screenshot directly into your system

Android Studio allows you to capture screenshots of your device and save it into your system. Although, if you are a person who likes to automate stuff, the following command is for you.

The exec-out from the following command redirects the output to our system’s shell, rather than the phone’s shell, allowing us to directly save the captured image into our system.

adb exec-out screencap -p > screen.png

4) Grant/Revoke permissions to applications

When working with run-time permissions, we usually need to grant/revoke permissions multiple times to ensure all scenarios are working as expected. This can be done from the system app settings UI for the specific application.

Why go through the hassle of opening up the app settings every time you need to change permissions when you can automate it? The following command allows you to do exactly that.

adb shell pm [grant|revoke] <package-name> <permission-name>Eg: 
adb shell pm grant com.example.app android.permission.CAMERA

5) List all installed application packages on the device

The following command can be used to list out all the installed application packages on the device. Some options used along with this:

  • -3: Lists only 3rd party applications installed by the user
  • -f: List the path to the installed APK
adb shell pm list package -3 -f 

--

--