I’m currently working on a timer project. Basically, it’s rather simple: the user inputs a time, the time’s running out and the user gets a fullscreen notification (simple fullscreen activity with a textview and sound). Said notification is called by a background service, to ensure it’s being called even when the user’s doing something else.
Now, everything runs perfectly until the screen locks. I can’t get that thing to unlock whatever I try.
Finally, I set following flags(inside the notification activity, which is being called):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timer);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
...
But even with that, the keyguard won’t disable and the notification won’t be shown. Only thing that happens is the screen turning on.
Am I missing something here?
P.S.: I already tried using a wake lock, which also didnt work.
Hope you solved your answer, but for the sake of other might run into your situation, try setting the flags after the setContentView() method, and using setFlags() method.
This is what I do in my app and it works.