Android What Permissions Required to Call Powermanager.Gotosleep(N) Put Device in Sleep Mode

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



Leave a reply



Submit