Simulate Low Battery & Low Memory in Android

How to simulate low battery in Android devices

simulating low battery is not provided by default as far as i know.(if you are using eclipse as im).
But if you are in linux , u can use telnet to connect to ur localhost emulator and perform 'Power' actions.(not used them maybe u can give a try)
http://handycodeworks.com/?p=46

But u dont have to go through that process. Just register a broadcast receiver for ACTION_BATTERY_LOW, and it is guaranteed to be called in low battery scenarios.

Hope it helps

EDIT:

here is the direct answer (assuming that ur running windows).

Enable 'telnet' on windows if you havent already.

Control panel-->programs-->under 'programs and features' select 'turn windows features on or off'-->it opens a new window select 'telenet client' and click on OK.

start command prompt with admin rights(in AllPrograms search for 'cmd' and right click on it and select run as admin).

then use this commands

1)telnet localhost 5554 //where 5554 is your emulator id, which is displayed top left   corner of ur emulator
2)power capacity 10 //set the battery level to 10%
3)power ac off //turns off charging mode

Now you can see a low battery dialog in emulator.

How do you simulate low memory in the Android emulator?

Invoke ulimit command from the shell.

ulimit -Sv 10000

This will set current memory limit to 10 000 Kb, so that all apps invoked from this shell afterwards won't be able to access more memory.

Simulating low memory in Android (ulimit command)

Simulate is a broad term however as your question tag indicates you want to do this on an avd, the following might help you out if you are using eclipse.( I am sure there is a way to do the same in other IDE's as well).

Define Eclipse use of Heap Size

You can always increase or decrease the amount of memory available to eclipse. Doing this you can reduce the amount of memory available for the avd to function. This link quite aptly describes how to manipulate the memory available for eclipse to use.

You can choose whatever max memory "size" eclipse is allowed to use, therefore your avd is also bounded by that limitation. This will make the whole process of development slow however and might even cause a java heap size error. However I think that's the error you want to "simulate" anyway.

generate a low battery alert programmatically in Android

ACTION_BATTERY_LOW is a system's broadcast action, so you won't be able to generate it for security reasons - at least not on a "regular" device



Related Topics



Leave a reply



Submit