2

I need to show message on top of the lock screen, like Android Alarm Clock is displaying full screen of the alarm, when it's the time to wake up.

Here is a photo of one of the screen popup when there is alarm:

Screenshot

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Oded BD
  • 2,788
  • 27
  • 30

2 Answers2

4
Window window = getWindow();

window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ranajit Sawant
  • 181
  • 1
  • 6
2

https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

You are looking for the method setFullScreenIntent(). This allows a notification to display over whatever is being viewed. Remember, this is only for extremely critical notifications (phone call or alarm clock) so only do this if absolutely necessary.

Shadesblade
  • 782
  • 5
  • 5
  • My intent is open only when I click the notification. It is not like alarm clock or whatsapp that the window is popping without any click. This is my code: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.play) .setContentIntent(contentIntent) .setSound(defaultSoundUri) .setContentTitle("Bring me front!") .setContentText("Bring me!!! BRING!!!") .setFullScreenIntent(contentIntent, true); – Oded BD Oct 26 '16 at 20:15
  • 2
    Is it a heads-up notification? From the link: "On some platforms, the system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device." This is how it works for all apps. – Shadesblade Oct 26 '16 at 20:19
  • Yes, but is there a way to force showing the intent? I need to display image and I can't do it with notification. And it always displaying heads-up notification, even if my phone is locked or is idle with screen on.. I'm asking because alarm clock and whatsapp is doing just this. Thank you @Shadesblade for helping me so much – Oded BD Oct 26 '16 at 20:31
  • If you want to circumnavigate Androids notification handler when the screen is on, you probably need to do something similar to Facebook's chatheads with SYSTEM_ALERT_WINDOW. I honestly don't know about when the screen is locked, setting setFullScreenIntent() should handle that. – Shadesblade Oct 26 '16 at 20:36
  • 1
    Here's a small guide for doing something in coordination with SYSTEM_ALERT_WINDOW: http://androidsrc.net/facebook-chat-like-floating-chat-heads/ – Shadesblade Oct 26 '16 at 20:37