How to make status-bar untouchable in android? -
i trying make lock screen android, versions greater honeycomb. have been searching working solution since month haven't been successful. i'll specific situation.
- in specific activity want status bar visible untouchable @ all. in other words user should not able pull down.
- i don't want solution collapse status bar when activity loses focus. doesn't work! still able pull down status bar after 1 or 2 tries on galaxy note-2.
- i don't want put activity in fullscreen mode. hide status bar want visible.
- i know possible. there threads saying it's impossible so. know it's possible because there other custom lock screens implement same. (eg. dodol locker, locker+, etc.)
i appreciate working code.
thanks in advance.
lets give try not make status bar untouchable stop getting dragged,first give permissions in mainfest file expand_status_bar
<uses-permission android:name="android.permission.expand_status_bar" />
declare these variables in activity :
// keep track of activity's window focus boolean currentfocus; // keep track of activity's foreground/background status boolean ispaused; handler collapsenotificationhandler;
it ask override following method,override it
@override public void onwindowfocuschanged(boolean hasfocus) { currentfocus = hasfocus; if (!hasfocus) { // method handles loss of window focus collapse_now(); } }
define collapse_now method
public void collapse_now() { // initialization 'collapsenotificationhandler' if (collapsenotificationhandler == null) { collapsenotificationhandler = new handler(); } // if window focus has been lost && activity not in paused state // valid check because showing of notification panel // steals focus current activity's window, not // 'pause' activity if (!currentfocus && !ispaused) { // post runnable delay - set 300 ms collapsenotificationhandler.postdelayed(new runnable() { @override public void run() { // use reflection trigger method 'statusbarmanager' object statusbarservice = getsystemservice("statusbar"); class<?> statusbarmanager = null; try { statusbarmanager = class.forname("android.app.statusbarmanager"); } catch (classnotfoundexception e) { e.printstacktrace(); } method collapsestatusbar = null; try { // prior api 17, method call 'collapse()' // api 17 onwards, method call `collapsepanels()` if (build.version.sdk_int > 16) { collapsestatusbar = statusbarmanager.getmethod("collapsepanels"); } else { collapsestatusbar = statusbarmanager.getmethod("collapse"); } } catch (nosuchmethodexception e) { e.printstacktrace(); } collapsestatusbar.setaccessible(true); try { collapsestatusbar.invoke(statusbarservice); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); } catch (invocationtargetexception e) { e.printstacktrace(); } // check if window focus has been returned // if hasn't been returned, post runnable again // currently, delay 100 ms. can change // value suit needs. if (!currentfocus && !ispaused) { collapsenotificationhandler.postdelayed(this, 100l); } } }, 300l); } }
handle activity's pause state
@override protected void onpause() { super.onpause(); // activity's been paused ispaused = true; } @override protected void onresume() { super.onresume(); // activity's been resumed ispaused = false; }
Comments
Post a Comment