Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a device to sleep mode

Tags:

android

I am doing one application for that I need to put a android device to sleep mode. How to put a device to sleep mode and how to wake-up a device when it is in sleep mode.

Thanks in advance

like image 934
shiv1229 Avatar asked Jan 16 '12 16:01

shiv1229


1 Answers

How to put a device to sleep mode

You don't. You allow the device to fall asleep of its own accord, when the user is done working with it, based upon the user's preferences as set up in Settings.

how to wake-up a device when it is in sleep mode.

If it is supposed to wake up at a certain time, use AlarmManager with a getBroadcast() PendingIntent. The device will stay awake long enough for your BroadcastReceiver to be called with onReceive(). Once onReceive() returns, the device can fall back asleep. If your work is too long to do in onReceive(), you will need to delegate that work to some other component (e.g., an IntentService) and use a WakeLock to keep the device awake long enough for you to complete the work and no longer.

like image 94
CommonsWare Avatar answered Oct 11 '22 12:10

CommonsWare