Published on
/
2 min read

Useful Android Bash Commands

Authors

Preface

I thought I'd share with you some everyday Bash commands that help with Android development.

alias atop="adb shell dumpsys activity top"

capture() {
  adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > ./$1.png
}
alias capture=capture

setLocale() {
  adb shell "su -c 'setprop persist.sys.language $1; setprop persist.sys.country $2; stop; sleep 5; start'"
}
alias setLocale=setLocale

I put these into my .bash_profile file so that they can be used whenever. Don't forget to run source ~/.bash_profile to update your terminal.

atop

This command will have adb output a bunch of debug information about the current Activity on the phone. It's great to get a quick sense of your View hierarchy. It also shows which fragments are being used and some state information.

capture

I'm no Perl wizard, I actually found this command here. Running capture my_picture will output my_picture.png to the current directory. Very helpful for taking screenshots and not having to transfer them from the device.

setLocale

You will need root access to run this command, but don't worry because Genymotion devices are rooted by default. This is a quick way to change the langauge AND country of a device. See Android's Locale class for more information on that.