我正在尝试在广播接收器中获取唤醒锁,以便我的闹钟应用程序可以将手机从睡眠中唤醒。它在以下代码中的以下行崩溃:
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
有什么想法吗?有一个更好的方法吗?谢谢!
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
public class RepeatingAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
AlarmAlertWakeLock.acquireCpuWakeLock(context);
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();
}
}