disabling and hiding android navigation bar/notification menu permanently

后端 未结 3 1985
渐次进展
渐次进展 2021-01-20 15:24

Im developing an android application for a school and i want this application when opened to prevent the user from doing anything on the device except what im offering insid

3条回答
  •  滥情空心
    2021-01-20 15:57

    Its possible

    To disable the Status NotificationBar:

    You need to place a view on top of the notification bar, so that we hijack the touch events to the Status notification bar. Without further ado, here is the code:

    mView= new TextView(this);                                       
    mView.setText(".........................................................................");                       
    
    mLP = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            100,
            // Allows the view to be on top of the StatusBar
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
            // Keeps the button presses from going to the background window
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            // Enables the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);
    
    mLP.gravity =  Gravity.TOP|Gravity.CENTER;      
    
    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    mWindowManager.addView(mView, mLP);
    

    And since you are using the system overlay window, you need the permission:

    
    

    Note:

    Do not make your app full screen, as the versions above 17, which supports immersive mode, will screw this approach.

提交回复
热议问题