Can anyone tell me how can I simulate low battery in my rooted device?
I gone through this question but did not find much information on this.
Is the battery removable? If so, get a spare battery and keep it in a low charge state for your low battery testing.
You can make an ActivityInstrumentationTestCase2 and call the various onPause
, onStop
, and onDestroy
methods to simulate a low memory situation only the onPause
is guaranteed to be called:
In situations where the system needs more memory it may kill paused processes to reclaim resources. Because of this, you should be sure that all of your state is saved by the time you return from this function. In general onSaveInstanceState(Bundle) is used to save per-instance state in the activity and this (onPause) method is used to store global persistent data (in content providers, files, etc.)
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.
With the Android Emulator's Extended Controls, it's now possible to set the battery level with a GUI slider called "Charge Level."
To access this, start the emulator. Then click the "..." at the bottom of the settings panel (which hovers to the right of the emulator).
This opens the Extended Controls panel which contains a "Battery" menu item:
The Charge Level slider goes from 0 to 100%. You can also simulate failed/overheated/etc physical battery, and being off the charger by adjusting the other drop down controls.
Use the following commands
To simulate the device being unplugged:
adb shell dumpsys battery unplug
To test how the device behaves under low power conditions:
adb shell settings put global low_power 1
Once you have finished your testing, you can undo your manual device settings with this command:
adb shell dumpsys battery reset
The link from @user2240369 actually leads you to the right answer. You should do this:
telnet localhost 5554 #or wahtever port you are using
power capacity 60