I have an application that sets a repeating alarm and I would like it to wake the device, unlock the keyguard, do something and then release the lock ready to repeat again on the next alarm. It seems to work but the handset only wakes and unlocks the keyguard the first time the alarm is triggered, each time the alarm repeats after that it does not turn the screen on and unlock although the audio file the alarm triggers does play each time. What am I missing?
public class RepeatingAlarmWake extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Wake up!");
wl.acquire();
KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
keyguardLock.disableKeyguard();
PlayAudio2.INSTANCE.PlayAudio();
wl.release();
}
}