Changing the battery percentage in an AVD (android virtual device) emulator

First I will briefly show how to react to the battery percentage change in your application, and then show how to change the battery level in the android emulator (AVD).

Reacting to the battery level change in your program

We need to register our application to receive the intent when the battery level information is changed, we do this by adding the following line into our onCreate method of our activity (or some other instance):

		new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

This will run mBatInfoReceiver when the battery level is changed, so we now need to create this method in our activity (or some other instance). The function creates a broadcast receiver to handle the information when the intent is sent for the battery status changing.

		private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){

			public void onReceive(Context arg0, Intent intent) {
			      int level = intent.getIntExtra("level", 0);
			      // TODO: Preform action based upon battery level


Changing the battery level in AVD

First we need to find the port so that we can address the emulator, this will be shown in the titlebar of the AVD.

Froyo running in an AVD (android emulator)

Froyo running in an AVD (android emulator)

Zooming in:

AVD title shows the port "5554:froyo"

Using the port from the AVD found above we can use telnet to control certain aspects of the avd see this android reference for a full reference.

telnet localhost 5554
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
Android console command help:

    help|h|?         print a list of commands
    event            simulate hardware events
    geo              Geo-location commands
    gsm              GSM related commands
    kill             kill the emulator instance
    network          manage network settings
    power            power related commands
    quit|exit        quit control session
    redir            manage port redirections
    sms              SMS related commands
    avd              manager virtual device state
    window           manage emulator window

try 'help ' for command-specific help

Some more information on the power commands:

help power
allows to change battery and AC power status

available sub-commands:
    display          display battery and charger state
    ac               set AC charging state
    status           set battery status
    present          set battery present state
    health           set battery health state
    capacity         set battery capacity state

So now you can change the battery level in the avd using power capacity percentage

power capacity 100
power capacity 99
power capacity 60
power capacity 20
power capacity 0

As you change the battery capacity you should notice that your AVD is responding, just by looking at the battery indicator in the status bar, and your program will react if you have replaced the //TODO: code with something that reacts when the onReceive is called.


  1. Anu


    Can you tell me where i should enter this “telnet localhost 5554”, in the command prompt I moved tools directory and gave this command, but i am getting ‘telnet’ not supported 🙁 Help me in this.


  2. mat

    @Anu, It depends what operating system you are using. I was under the impression windows has telnet by default (perhaps you don’t have access to it?).

  3. Sunny

    I was having trouble getting telnet to work. I would receive the error “‘telnet’ is not recognized as an internal or external command, operable program or batch file”. To fix this issue, go to Add/Remove Programs, Turn Windows Features on and off, then check Telnet Client. This should fix the problem.

  4. Amit

    Awesome.. works great:)

  5. Mehmet Akif Tütüncü

    Thanks for the information. It works but I have a problem. When I connect via telnet, my emulator gets unresponsive. It changes the battery status as I expect, but then I cannot do anything else in emulator, it gets frozen. I use Ubuntu 12.04 and Android 4.0.3 emulator with Intel x86 system image. Do you know why might this be happening?


  6. Giselle


    I tried it but the emulator stops working on writing the power capacity 100 command. I tried all other commands and it works fine. Only the power command causes the emulator to stop working. Any help would be appreciated.

    Thank you

  7. anzeljg
  8. Marcus Becker

    If you want, you can use my friendly application to send commands to AVD.

    Android Graphical Console.

  9. karthik

    in telnet, you may need to use

    power capacity XX%

    to make it work.

    for example

    power capacity 25%

    (tested in windows 8)

  10. Srinivas

    I enabled hw.battery=yes in .android/avd/config file and it works so nice

    Thank you very much for this tip

  11. […] Changing the battery percentage in an AVD (android virtual … – First I will briefly show how to react to the battery percentage change in your application, and then show how to change the battery level in the android emulator (AVD)…. […]

  12. […] power capacity 100 is what you should set for emulator , no we do not want to see anything less than that […]

Leave a Comment

Your email address will not be published. Required fields are marked *