Search code examples
androidandroid-viewandroid-windowmanagerandroid-8.0-oreo

Show views above lockscreen using window manager in Android O?


My app shows views above the lockscreen, until now I used the following code:

windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 65794, -2);
windowParams.type = Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
windowManager.addView(frameLayout, windowParams);

This code doesn't seem to work anymore on Android O, instead, now the lockscreen is shown above the view, and the view only becomes visible after the user swipes away the lockscreen. Granted, it could just be a bug since Android O is still in beta, but it's also possible that I missed one of Googles notes about "what's new in O".


Solution

  • It's no longer possible to draw over the lockscreen and other important UI elements (status bar, etc), Google removed this feature in Android O.

    Source: https://issuetracker.google.com/issues/36574245