Friday, 20 February 2015

Background

I have written a couple of posts before on Android Application development, debugging and other general concepts. As you know Android is just an operating system running on Linux kernel customized for resource constrained environment like that of handheld systems. Before you roll out your application to other users you need to test it on various models (with different configurations). This is where you Emulator comes into picture. You can create a emulator that suits your testing requirement. In this post we will cover some of the events that we can simulate with emulators like setting batter to low etc. So basically we will use a telnet to connect to Android virtual device and issue commands to simulate various events.

Creating an Android virtual Device

Lets start by creating an Android virtual device. Open your Eclipse which come as a pert of ADT bundle.

Go to

Windows -> Android Virtual Device Manager

I currently don't have any emulators. So the manager shows no emulators.

Go ahead and create one. Click on create button on the right. Fill in the configuration details as per your requirements.

After successful creation of AVD start it. Wait for it to initialize (It may take couple of minutes). My Emulator looks like the following at startup -

Now lets connect to it via telnet. See the number at the top of the Emulator ? (5554:athakur_Nexus) This number (5554) is the port number emulator is running on. You can do various action by connecting to it via telnet. Connecting is very simple. Simply type following in command prompt -

telnet localhost 5554

and you get a 'OK' response. Notices the 3G network symbol at the top right corner. Lets change it to 2G or edge. Command for that is -

network speed edge

To change it back to 3G you can use command -

network speed full

You can also change the battery status of your emulated device. Notice the battery icon. It about little more than 50% charged and battery is still charging (power is connected).

Lets first reduce the battery level. To do so you can use following command -

power capacity 4

and notice how battery level drops.

Battery is still charging. Notice the lightning symbol inside battery icon. Lets stop the charging. To do so use the following command -