Thursday, September 9, 2010

How to set battery status of Android Emulator using the Emulator Console

In last two exercise "Detect Battery Level" and "Detect Battery Info", the apps about battery checking have been built. We have to set the battery status on Android Emulator to check our apps. To change the battery status on Android Emulator, Emulator Console can be used.

To connect to the console of any running emulator instance at any time, use this command:

telnet localhost <console-port>

Where <console-port> is the number shown on your emulator.

Details of the usage, refer to the section Using the Emulator Console of the document Android Emulator.


ffxx68 said...

Hi very useful tricks, but I can't find where to set battery status from the console. Can you provide some guidance. Also, if possible, about how to GET status from console.

thanks a lot

Android Er said...

hello Fabio,

You cannot change battery status in Eclipse. To change battery status, you have to start a terminal (in Linux), type the command:
$telnet localhost 5554
where 5554 is the number shown on your emulator.

and then type commands, such as:
power display
power ac off
power status discharging
power capacity 25
you can type the command help to see the available command.

The setting you changed in console will change the status of Android emulator, so you can GET status by checking Android status.

ffxx68 said...

thanks AndroidEr for this clarification.

What I was actually trying to achieve is something different - I'd like to monitor battery info directly from the terminal, accessing the battery module, but I wonder if that is ever possbile...

thanks anyway!

Android Er said...

hello Fabio,

I have no idea for your case, sorry.

But, I wonder what's the purpose. In actual case, real phone is not built inside your system; so detect it for what?

Alina Lapina said...

what should I do to fix:

'telnet' is not recognized as an internal or external comand, operable program or batch file.


Please help.
The app is running, and I've got:
emulator: device fd:640
HAX is working and emulator runs in fast virt mode
creating window 115 127 433 770
emulator: emulator window was out of view and was recentered.

Thanks in advance!