Lock / disable status bar on Android tablet / mobile device

I saw the Kioware and SureLock apps. They simply block every control on the tablet. I know about back button return and handling home and recent task parameters. But I'm not sure how they managed to control the settings on the system panel. Settings are displayed for a few seconds and then disappear. In the same way, the status bar of the mobile phone that appears during deletion should be locked.

If anyone has an idea, share it. Any advice / help is appreciated.

See the portion of the highlighted image that I need to lock / unplug

+6
source share
3 answers

Finally, I found a solution to this problem. onWindowFocus change I just closed the dialog boxes created by the system and my problem was resolved. Below is a sample code.

@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if(!hasFocus) {// Close every kind of system dialog Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeDialog); } } 

Update:

On the mobile device, the lock of the status bar displayed on the screen is used below.

 private Handler collapseNotificationHandler; @Override public void onWindowFocusChanged(boolean hasFocus) { boolean currentFocus = hasFocus; if (!hasFocus) { collapseNow(true,currentFocus); } } public void collapseNow(final boolean shouldCollapse, final boolean currentFocus ) { // Initialize 'collapseNotificationHandler' if (collapseNotificationHandler == null) { collapseNotificationHandler = new Handler(); } // If window focus has been lost && activity is not in a paused state // Its a valid check because showing of notification panel // steals the focus from current activity window, but does not // 'pause' the activity if (!currentFocus && !isPaused) { // Post a Runnable with some delay - currently set to 50 ms collapseNotificationHandler.postDelayed(new Runnable() { @Override public void run() { // Use reflection to trigger a method from '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 to API 17, the method to call is 'collapse()' // API 17 onwards, the method to call is `collapsePanels()` if (Build.VERSION.SDK_INT > 16) { collapseStatusBar = statusBarManager.getMethod("collapsePanels"); } else { collapseStatusBar = statusBarManager.getMethod("collapse"); } } catch (NoSuchMethodException e) { e.printStackTrace(); } collapseStatusBar.setAccessible(shouldCollapse); try { collapseStatusBar.invoke(statusBarService); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } // Check if the window focus has been returned // If it hasn't been returned, post this Runnable again // Currently, the delay is 50 ms. You can change this // value to suit your needs. if (!currentFocus && !isPaused) { collapseNotificationHandler.postDelayed(this, 50); } } }, 0); } } 

"isPaused" boolean, which sets true when the application is paused.

0
source

The trick is to add a transparent user view that overlays the system panel so that all user interactions like touch, drag will be consumed by the user view.

Here is the working code:

 windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); statusBarOverlay = new CustomViewGroup(this); final WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(); localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; localLayoutParams.gravity = Gravity.TOP; localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | // this is to enable the notification to receive touch events WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | // Draws over status bar WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity); localLayoutParams.format = PixelFormat.TRANSPARENT; windowManager.addView(statusBarOverlay, localLayoutParams); 

Custom ViewGroup :

 public class CustomViewGroup extends ViewGroup { public CustomViewGroup(Context context) { super(context); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return true; } } 

I myself made a lock function for my application, although I split the lock function into another application for many reasons. You can request additional information, and I will put them here if necessary.

+3
source

You can try adding a transparent View to your desired position using the WindowManager (follow this example). This way you will capture any tap events from the user.

Be sure to set the appropriate flags / type , because you need to impose system panels:

  WindowManager.LayoutParams dismissParams = new WindowManager.LayoutParams( viewWidth, viewHeight, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, //you can also try with TYPE_SYSTEM_OVERLAY, TYPE_SYSTEM_ERROR WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, PixelFormat.TRANSPARENT); 
+2
source

All Articles