Trouble with PowerManager.goToSleep()
I have done this but it works at random on several android 4.0.x plaforms.
powerManager.goToSleep(SystemClock.uptimeMillis() + timeMs)
Did anyone managed to use the method the way he has intended to?
Edit:
It seems the right answer was what figure in the code below:
public void sleepFor(long time, Context context) {
//Create a new PendingIntent, to wake-up at the specified time, and add it to the AlarmManager
Intent intent = new Intent(context, this.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent wakeupIntent = PendingIntent.getActivity(context, CODE_WAKE_UP_DEVICE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// CODE_WAKE_UP_DEVICE is a dummy request code.
AlarmManager am = getAlarmManager();
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + time, wakeupIntent);
powerService.goToSleep(SystemClock.uptimeMillis() + 1);
}
Attempting to put Android device to sleep, but the PowerManager does not contain a goToSleep(long) method
You can use the DeviceAdministrator , but you need the user to grant you those rights.
What happens to an Android service when PowerManager.goToSleep is called?
so does that imply that the service will be destroyed and not started again?
No. It implies that the service is unchanged. All sleep mode does is stop the CPU.
How to put Android to standby programmatically?
If you're developing your own ROM or you have a rooted phone (it's need to be checked which user is able to do this) then you should have a look to the PowerManager.goToSleep functionality. Here is a discussion about this function in the Google Groups. And here you can read about this particular permission.
Related Topics
How to Execute a Method by Clicking a Notification
Inserting Contacts in Android 2.2
Set Permission for Getting User's Email Id from Facebook Login
Receive Mms Messages in Android Kitkat
Broadcast Receiver to Detect Application Start
Why Is the Android Test Runner Reporting "Empty Test Suite"
What Are the Differences Among Internal Storage, External Storage, Sd Card and Removable Storage
How to Hide System Bar on Android Ics
Why Is Android Webview Refusing User Input
Is Google's Android Opengl Tutorial Teaching Incorrect Linear Algebra
Android Copy/Paste from Clipboard Manager
How to Find Intent Source in Android
Change Background of Progressdialog
Android Overlay to Grab All Touch, and Pass Them On
Limit Scrolling and Zooming Google Maps Android API V2
Convert Xml to JSON Object in Android
What Is the "Ignoring Innerclasses Attribute" Warning Output During Compilation