I want to display an Activity in front of the Lockscreen. I tried with this code in my onCreate medthod:
super.onCreate(savedInstanceState);
Window window = getWindow();
window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setContentView(R.layout.test);
That works great for Activities which are displayed over the whole screen but I want to build an Activity which is only 200px heigh. I thought I can match it with this code:
super.onCreate(savedInstanceState);
Window window = getWindow();
LayoutParams layout = new WindowManager.LayoutParams();
layout.copyFrom(window.getAttributes());
layout.height = 200;
window.setAttributes(layout);
window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setContentView(R.layout.test);
But then the Activity is not visible in front of the lockscreen. If I unlock the phone the Activity is displayed directly. Any ideas why and how I can fix this?
EDIT: I think it has something to do with the window floating FLAG. If this flag is set (and I think it will when I change the size) the activity is not displayed over the lockscreen. But this is only a presumption. Any ideas or a workaround to fix this?
Lockscreen
(partially) behind the activity? – VikramKeyguardManager myKeyGuard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); myLock = myKeyGuard.newKeyguardLock("tagName"); myLock.disableKeyguard();
- with the permission in the Manifestandroid.permission.DISABLE_KEYGUARD
. Then alternatively tryWindow window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
. – g00dy