gpt4 book ai didi

android - PowerManager.newWakeLock() 抛出 IlleagelArgumentException

转载 作者:太空狗 更新时间:2023-10-29 15:30:33 32 4
gpt4 key购买 nike

我正在尝试获取唤醒锁,但是当我调用 PowerManager.newWakeLock() 时,我收到 IlleglArgumentException。

这是我用来获取的代码

private void setWakeLock(Context context)
{
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
SoundAlarmActivity.WakeLock = pm.newWakeLock(
PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "Alarm");
SoundAlarmActivity.WakeLock.acquire();
}

这是 logcat:

09-28 12:53:09.704: ERROR/AndroidRuntime(702): java.lang.IllegalArgumentException
09-28 12:53:09.704: ERROR/AndroidRuntime(702): at android.os.PowerManager$WakeLock.<init>(PowerManager.java:223)
09-28 12:53:09.704: ERROR/AndroidRuntime(702): at android.os.PowerManager.newWakeLock(PowerManager.java:365)

最佳答案

试试这个:

private void setWakeLock(Context context)
{
PowerManager pm = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
SoundAlarmActivity.WakeLock = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "BusSnoozeAlarm");
SoundAlarmActivity.WakeLock.acquire();
}

PowerManager.ACQUIRE_CAUSES_WAKEUP 不适用于部分唤醒锁,因此您必须确保在定义所需的唤醒锁类型时使用的是 FULL_WAKE_LOCK。

关于android - PowerManager.newWakeLock() 抛出 IlleagelArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3812919/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com