How to automate your Android using ADB

It's quite frustrating to repeat similar task on multiple android devices. Android-OS provides a very easy method to simulate key/button press/release events via Android Debug Bridge. ADB can play very handy role in case of debugging, UI automation and logging.

What is ADB?

Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
  • A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
  • A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
  • A daemon, which runs as a background process on each emulator or device instance.

“How to automate your Android device”

The “adb shell input” command can be used to automate any attached Android device by sending simple commands and input over USB. The syntax is:
input [<source>] <command> [<arg>...]
The various sources are:
  • trackball
  • joystick
  • touchnavigation
  • mouse
  • keyboard
  • gamepad
  • touchpad
  • dpad
  • stylus
  • touchscreen
Depending on your requirement you can select the appropriate input source.
We can send key codes as input events using “adb shell input key event <keycode>” using the following list of key codes:
input keyevent <event_code>
we need to find out the event-code that maps to the h/w key we want to simulate. The following table summarizes all the supported keycodes in Android:  

1 comment:

  1. The blog gave me idea to auto mate android using ADB my sincere thanks for sharing this post and please continue to share this kind of post
    Android Training in Chennai

    ReplyDelete