我正在尝试将设备置于睡眠模式一段时间,例如x,通过调用..
powerManager.goToSleep(xNumberOfMilliseconds);然而,api似乎从来没有一致地工作过,并且从来没有超过1000毫秒的时间量。我被难住了。我拥有适当的权限,我的应用程序在清单中将其sharedUserId设置为"android.uid.system“,并且应用程序使用与固件本身签名相同的密钥(平台密钥)进行签名。
这是一个非常简单的API调用,所以我真的不知道到底出了什么问题。我在运行Android2.3的设备和运行Android3.2的设备上都遇到过这个问题。
有什么想法吗?
发布于 2012-08-15 00:38:44
我已经这样做了,但它在几个Android4.0.X平台上随机工作。
powerManager.goToSleep(SystemClock.uptimeMillis() + timeMs)有没有人成功地使用了他想要的方法?
编辑:看起来正确的答案是下面代码中的数字:
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);
}发布于 2011-12-06 18:37:47
( ContentResolver cr= getContentResolver);
android.provider.Settings.System.putInt(cr,android.provider.Settings.System.SCREEN_OFF_TIMEOUT ,1000);
发布于 2012-01-13 06:28:36
根据documentation的说法,当前系统时间比期望的睡眠持续时间更适合goToSleep():
powerManager.goToSleep(SystemClock.uptimeMillis())https://stackoverflow.com/questions/8398304
复制相似问题