ADB Cheat Sheet

Take screenshot of the only emulator/device, and copy the screenshot to clipboard(so we can paste it directly somewhere)


adb exec-out screencap -p > screen.png && osascript -e 'set the clipboard to POSIX file "'$(pwd)'/screen.png"'
If you want to add it as an alias, in ~/.zprofile file(or whichever file it is for you), add these lines:

function ss() { adb exec-out screencap -p > screen.png && osascript -e "set the clipboard to POSIX file \"$(pwd)/screen.png\"" }


Lists all settings

adb shell settings list global


enables "show taps" on the UI

adb shell settings put system show_touches 1


To set animation duration to 10x
adb shell settings put global animator_duration_scale 10
adb shell settings put global window_animation_scale 10
adb shell settings put global transition_animation_scale 10


set the battery state as unplugged

adb shell dumpsys battery unplug


To set the battery percentage

adb shell dumpsys battery set level 65

http://mikepalarz.me/2019/04/dumpsys-battery


set the battery state as what is original(not so sure about this, you can try it out)

adb shell dumpsys battery reset


Return 1 if device is in battery saver mode, else returns 0

adb shell settings get global battery_saver_mode


To show list of activities in backstack. I have discovered this command with lot of research.

adb shell settings put global zen_mode 1
adb shell "pidof com.google.android.wearable.sysui | xargs kill"
adb shell dumpsys activity activities| grep "* Hist"


Command for accessibility

https://gist.github.com/mrk-han/67a98616e43f86f8482c5ee6dd3faabe


Enable wifi

adb shell svc wifi enable


This is not working.Haven't found a right solution to this.

adb shell svc wifi disable


Take Screenshot of current emulator and show it

adb exec-out screencap -p > screen.png && open screen.png


List all the installed packages:

adb shell pm list packages -f


Start find my phone activity from adb

adb shell am start -n "com.google.android.gms/.mdm.RingMyPhoneActivity"


Disable watch tutorial and need for companion.Use both the following commands.

While you are in the "Tap to begin" screen(before the language selection screen), run the following command. Run the first command and

wait till tutorials screen appears then run the second command.

adb shell am broadcast -a com.google.android.clockwork.action.TEST_MODE
adb shell am broadcast -a com.google.android.clockwork.action.TUTORIAL_SKIP


Turn off talkback

adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService


Turn on talkback

adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService


Click the home button

adb shell input keyevent 3


Swipe on the screen from (x1,y1) to (x2,y2) for t duration

adb shell input touchscreen swipe x1 y1 x2 y2 t

Example of a single finger horizontal swipe for 500ms:
adb shell input touchscreen swipe 356 186 10 186 500

For Vertical upwards swipe:

adb shell input touchscreen swipe 356 186 356 0 500


Changing language of device:

adb shell "setprop persist.sys.locale hi;"

adb reboot


This website has a great collection of adb commands:

Comments

Popular posts from this blog

Capturing Screen of Android Device using ADB

Enabling Internet in Android Emulator