android – 从广播接收器获取唤醒锁定的问题

我有个问题.我正在尝试让广播接收器获得唤醒锁定,以便我的闹钟将手机从睡眠模式唤醒.

在下面的广播接收器中,程序在“scpuWakeLock.acquire()”行上遇到“source not found”崩溃;当AlarmReceiver调用类“AlarmAlertWakeLock”时.
知道发生了什么事吗?有没有更好的方法来做我想做的事情?

一个文件中:

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;
        }
    }
}

解决方法

没关系,我想出来了 – 我需要为清单添加唤醒锁定权限:

uses-permission android:name =“android.permission.WAKE_LOCK”

现在工作正常!

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...