Friday 20 February 2015

Using Android Emulator to test your Android Application

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 -
  • battery status not-charging (Usage: "status unknown|charging|discharging|not-charging|full")
You can also simulate sms.  I am going to send a dummy message from telnet and you should see it as a proper message received in the emulator. Command for the same is -
  • sms send 9999999999 "Hi! - From Open Source For Geeks" (Syntax : sms send <phonenumber> <text message>)




You can even change your  coordinates on the map with following command -

  • geo fix 2.00 39.12
It is also possible to make a call from one emulator to  another. Simple go to dialer and dial port number of the other emulator. Emulator number running with that port will receive the call.






These are only some command. To get a full list of command you can type help after connecting to telnet -


Note :

  • You can reorient your device in the emulator by pressing Ctrl+F12 (Command+F12 on Mac). When this happens and your current Activity is killed and restarted.

Related Links

t> UA-39527780-1 back to top