Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate sleep mode on Android emulator

Some users of my Android application report bugs when the mobile enters sleep/power saving mode.

I would like to test that issue on the Android Virtual Device. Is it possible to simulate the mobile entering in sleep/power saving mode on the AVD ?

Thanks in advance.

like image 552
Arnaud Avatar asked May 07 '12 03:05

Arnaud


People also ask

How do I lock my emulator screen?

To reach the lock screen of Android Emulator, in recent emulators (using Android Studio 2.3) just click the "power" button in the Emulator. You'll get a black screen. Click it again and there it is, your lock screen.

How do I simulate my Android phone?

Emulator for native development with Android StudioIn the Android Studio toolbar, select your app from the run configurations drop-down menu. From the target device drop-down menu, select the device that you want to run your app on. Select Run ▷. This will launch the Android Emulator.

What is sleep mode in Android Studio?

That's why when LCD screen power is off (that means user is not interacting with phone), with in fraction of seconds CPU will also go to a mode (sleep mode) where it does minimal work and saves battery power.

How do I simulate an app on Android?

To start the Android Emulator and run an app in your project: In Android Studio, create an Android Virtual Device (AVD) that the emulator can use to install and run your app. In the toolbar, select the AVD that you want to run your app on from the target device drop-down menu. Click Run .


6 Answers

Try the following on emulator

  1. Go to Settings
  2. Go to Developer options
  3. Un-check Stay awake (3rd option from the top)

The emulator will go to sleep after 1 min (default setting) if not changed.

Press the power button enter image description here to wake up the emulator.

Developer options is not enabled by default, to enable it, do the following:

  1. Go to Settings
  2. Click About emulated device
  3. Click Build number 7 times, you should be notified that Developer options is now enabled
  4. Go back and you should see Developer options
like image 197
Prabhakar Avatar answered Oct 06 '22 03:10

Prabhakar


On emulator, go Settings/Security/Screen lock change from 'None' to 'Swipe' enter image description here

Then, click 'power' button on right control bar to turn off screen, and press again to turn on screen. Now the lock screen will show up. enter image description here

like image 44
thanhbinh84 Avatar answered Oct 06 '22 04:10

thanhbinh84


The Power Button on the sidebar next to emulator will do it.

The hotkey on my Mac is ⌘ P

Note: You will need to set Lock Screen using Swipe instead of None

like image 24
user1884811 Avatar answered Oct 06 '22 03:10

user1884811


To put the device to sleep using command line, run: adb shell input keyevent 223

To wake the device from sleep using command line, run: adb shell input keyevent 224

For more info about key events you can send with ADB, check out the KEYCODE_... constants for KeyEvent, e.g.:

/** Key code constant: Sleep key.
 * Puts the device to sleep.  Behaves somewhat like {@link #KEYCODE_POWER} but it
 * has no effect if the device is already asleep. */
public static final int KEYCODE_SLEEP           = 223;

/** Key code constant: Wakeup key.
 * Wakes up the device.  Behaves somewhat like {@link #KEYCODE_POWER} but it
 * has no effect if the device is already awake. */
public static final int KEYCODE_WAKEUP          = 224;
like image 38
Jeff McKnight Avatar answered Oct 06 '22 04:10

Jeff McKnight


Somehow fn + F7 doesn't work on my mac. So what I use instead is:

adb shell input keyevent 26

This sends the POWER KEY event and will turn off the screen. Note: It will not show that the screen is off. Image wills tay. But you can't interact with it. As soon as you do adb shell input keyevent 26 again, you will see the lock screen indicating, that the device was off before.

like image 32
Patrick Boos Avatar answered Oct 06 '22 04:10

Patrick Boos


By pressing F7 you can emulate sleep mode in your emulator.

like image 22
neferpitou Avatar answered Oct 06 '22 04:10

neferpitou