java - Window type can not be changed after the window is added -
i'm trying make custom lock screen. so, there need not allow user press home button. in beginning write
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.lock_screen); getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on |windowmanager.layoutparams.flag_show_when_locked);
then override onkeydown
@override public boolean onkeydown(int keycode, android.view.keyevent event) { if ((keycode == keyevent.keycode_volume_down)||(keycode == keyevent.keycode_power)||(keycode == keyevent.keycode_volume_up)||(keycode == keyevent.keycode_camera)) { //this can stuff return true; //because handled event } if((keycode == keyevent.keycode_home)){ return true; } return false; }
here override onattachetowindow
@override public void onattachedtowindow() { this.getwindow().settype(windowmanager.layoutparams.type_keyguard_dialog); super.onattachedtowindow(); }
but it's giving me error illegalargumentexception: window type can not changed after window added. mistake?
how can handle home button?
there no "good" way handle home button "do nothing". have 2 options may or may not enough you:
- create own home launcher. users must select app home launcher.
- you create
service
add view window , gets plastered on top of else. see previous answer here "displaying" webview in service: android: using webview outside activity context. need modifyparams
fill screen , fixwindowmanager.layoutparams.flag_not_touchable
use right flags allow clicks. won't block home button disable it's functionality. lastly, might not work on android 5.0+ status bar's dropdown may overlay window.
Comments
Post a Comment