A few years ago, I wrote an alarm app that worked on Android 2, and I'm now trying to upgrade it to work on Android 4. Specifically, on the Samsung Galaxy S4.
On Android 2, if the phone was sleeping, it would wake the phone up and display a "Snooze or Dismiss" screen over the lock screen.
On Android 4, it wakes the phone up, but you have to unlock it, then open the notifications area, then click the alarm's notification, before you can hit "Dismiss."
I have always been using this code to do the waking:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
I have read 8 different stackoverflow questions on this matter. Most of them give the code above, which worked for me years ago in Android 2 but doesn't work in Android 4. But none of them have helped me solve this problem. Here are the questions that I read and tried:
Android: remove or disable programmatically the Lock Screen on Samsung Galaxy S2 device
How to display a fullscreen TYPE_SYSTEM_ALERT window?
How do I create an Activity that is visible on top of the lock screen
How to start a dialog (like alarm dimiss /snooze) that can be clicked without unlocking the screen
Android activity over default lock screen
android device locked, yet want alarm to sound and dialog to appear
Android dialog over lock screen
Show dialog with touch events over lockscreen in Android 2.3
Does anyone have any ideas about what's changed in Android 4 that may have caused this?
EDIT: Here is one of the simplest examples I've seen of an alarm dialog that doesn't come up "minimized." It does not, as written, appear over the lockscreen, but you can fix that with WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
It's written with a FragmentActivity and a DialogFragment, but it still works as an Activity. It uses an AlertDialog.Builder to make the dialog, and if you try to do it with an XML layout, it won't work. Why?
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
wptrafficanalyzer.in/blog/… It works by using a FragmentActivity and a DialogFragment. But why? Why won't this work with a full Activity? – Majoriemajority