How to automate Android settings

Inside a project of rollout of new mobile phone we had the need to automate some settings configuration to make android devices rollout quickly.

We used ADB and Monkeyrunner tools for accomplish this task. These tools are inside Android SDK:

Install Android SDK and from SDK Manager select both “Android SDK Tools” and “Android SDK Platform-tools”

Android SDK Manager

ADB can found on ..\Android\android-sdk\platform-tools

Before using ADB remember to enable Developer Menu and the USB Debug option:

With ADB you can perform various tasks against your Android device.
For example this script wait for a device and then install an app (MDM.apk) and remove some other unnecessary apps:

cd C:\Users\sysadmin\AppData\Local\Android\android-sdk\platform-tools
adb wait-for-device
adb install C:\Data\MDM.apk
adb shell pm uninstall
adb shell pm uninstall
adb shell pm uninstall

To browse all the apps installed you can use this command:

adb shell pm list packages

More commands can be found here: Http://

Then I used monkeyrunner for automate some configuration. Monkeyrunner can be found in this folder: ..\Android\android-sdk\tools
Then I downloaded two scripts to make using monkeyrunner easier:
Copy and into ..\Android\android-sdk\tools folder.

If you already connected your Android device via USB with USB_DEBUG enabled the run this command for record some actions:


Using the mouse perform the actions on MonkeyRunner Recorder screen then save the script clicking on the menu “Export Actions”. Save the file with file extension “.mr”. For example C:\Data\

To perform the same action you recorded again type this command:

monkeyrunner C:\Data\

Remember to insert some sleep after each action you recorded because probably your device is not so quickly as commands are sent by script.


Here a list of actions that you can type directly on your monkeyrunner script:

  • To press “HOME” Button:
  • To type something:
  • To Scroll Down:
  • To Scroll Left:
  • To wait 1 second:

Following some ADB notes:

  • connect adb over Wi-Fi
     adb shell setprop service.adb.tcp.port 5555 && stop adbd && start adbd adb connect 
  • Unlock your Android screen
     adb shell input keyevent 82 
  • Lock your Android screen
     adb shell input keyevent 6 adb shell input keyevent 26 
  • Open default browser
     adb shell input keyevent 23 
  • Keep your android phone volume up(+)
     adb shell input keyevent 24 
  • Keep your android phone volume down(-)
     adb shell input keyevent 25 
  • Go to your Android Home screen
     adb shell input keyevent 3 
  • Take Screenshot from adb
     adb shell screenshot /sdcard/test.png 
  • start clock app
     adb shell am start 
  • stop clock app
     adb shell am force-stop 
  • start wifi settings manager
     adb shell am start -a android.intent.action.MAIN -n 



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s