我有个问题.我正在尝试让广播接收器获得唤醒锁定,以便我的闹钟将手机从睡眠模式唤醒.
在下面的广播接收器中,程序在“scpuWakeLock.acquire()”行上遇到“source not found”崩溃;当AlarmReceiver调用类“AlarmAlertWakeLock”时.
知道发生了什么事吗?有没有更好的方法来做我想做的事情?@H_404_4@
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- public class AlarmReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(final Context context,Intent intent) {
- AlarmAlertWakeLock.acquirecpuWakeLock(context);
- }
- }
- import android.content.Context;
- import android.os.PowerManager;
- public class AlarmAlertWakeLock {
- private static PowerManager.WakeLock scpuWakeLock;
- static void acquirecpuWakeLock(Context context) {
- if (scpuWakeLock != null) {
- return;
- }
- PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- scpuWakeLock = pm.newWakeLock(
- PowerManager.PARTIAL_WAKE_LOCK |
- PowerManager.ACQUIRE_CAUSES_WAKEUP,"okTag");
- scpuWakeLock.acquire();
- }
- static void releasecpuLock() {
- if (scpuWakeLock != null) {
- scpuWakeLock.release();
- scpuWakeLock = null;
- }
- }
- }