私は問題があります。放送受信機にウェイクロックを取得させて、アラームが電話をスリープモードからウェイクアップさせようとしています。
以下の放送受信機では、AlarmReceiverによってクラス「AlarmAlertWakeLock」が呼び出されると、「sCpuWakeLock.acquire();」行の「sourcenotfound」でプログラムがクラッシュします。やろうとしているの?
1つのファイル:
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;
}
}
}