1

The method for kiosking an application by disabling pull and click of the status bar does not work on android 8. As anserwed on How to disable status bar click and pull down in Android?.

I have tested it on android 7 and less and it works, but the status bar still pulls down when pulled on android 8.

I didnt find any solution for the same. Please let me know if there is any solution that works for oreo also.

Thanks!

7
  • In Above link, User 2nd Option for Android Oreo and above. User can Pull down but it will immediately pull up. I am using 2nd option for the My Kiosk AApp. Commented Jan 7, 2019 at 5:35
  • its working, but is not restricted everytime. means i want to disable that.. that window tray will not open in any condition. Commented Jan 7, 2019 at 5:58
  • That is not possible In android Oreo and Above. Commented Jan 7, 2019 at 7:00
  • okay.. thanks. it is managable upto now.. can you tell me how can i implement this in all activities? Commented Jan 7, 2019 at 9:02
  • should i define this in all activities separately? Commented Jan 7, 2019 at 9:14

1 Answer 1

4

I am using below code in MainActivity.

//Global Declaration Handler collapseNotificationHandler; @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); Log.d(tag, "window focus changed"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { collapseNow(); } } 

Collapse Method

public void collapseNow() { try { // Initialize 'collapseNotificationHandler' if (collapseNotificationHandler == null) { collapseNotificationHandler = new Handler(); } // Post a Runnable with some delay - currently set to 300 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(true); try { collapseStatusBar.invoke(statusBarService); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } // Currently, the delay is 10 ms. You can change this // value to suit your needs. collapseNotificationHandler.postDelayed(this, 10L); } }, 10L); } catch (Exception e) { e.printStackTrace(); } } 
Sign up to request clarification or add additional context in comments.

5 Comments

I am also using this code.But my question is how can i achieve this in all activities. Do i have to implement the whole code in all the activities or can i do this in a single class and implement this?
i set only in main activity , it is working when i am in the main activity, but when i jump to any other activity then, it is not working
I will frame you the whole thing, i am making a gate application in which if I lock my app then it will be restricted to my app in the phone and if it is unlocked by password, then i have to disable all locks and enable notification bar. If i again lock the app, then i have to disable the bar.. This is the whole scenario
I solved it.. thanks for your help. I use a boolean and make it true in main activity when the app is running and when it got destroyed i change it to false and solved my problem.
1 thing i want to ask, this task is running in the background that making my app slow.. is there any solution for that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.