Search code examples
androidreflectionrootandroid-notificationsstatusbar

Android - Hide notification bar but keep navigation one


I'm creating a kind of Kiosk application for Android but I must disable the notification bar to avoid the customers to access Wifi, Bluetooth or GPS quick access.

So far I've rooted the device and disabled the com.android.systemui package to achieve that. The main issue is, as I got only virtual buttons to navigate, I can't go back or go to home screen. Basically I'm stucked on the application and I can't do anything.

I've used that code to disable the SystemUI package:

pm disable com.android.systemui

Then I've tried to disable the notification bar using the Java reflection API. So far, I've made that code but it doesn't work. Basically, it just throws an exception saying my application doesn't have the required permission android.permission.STATUS_BAR whereas it's written in my Manifest.

try
{
    Object service  = getSystemService("statusbar");
    Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
    Method collapse = statusbarManager.getMethod("disable", int.class);
    collapse.setAccessible(true);
    collapse.invoke(service, 0x00000001);
}
catch (Exception e)
{
    e.printStackTrace();
}

Did I make something wrong on that part of code ?

An alternative would be to create a System overlay to create my own navigation bar, but I haven't find a proper way to trigger a KeyEvent to the whole system as if it was the "real" buttons. But honnestly, I don't think this would be the best and cleanest solution to use.

Any help would be greatly appreciated.


Solution

  • In styles.xml:

    <resources>
       <style name="Theme.FullScreen" parent="@android:style/Theme.Holo">
       <item name="android:windowNoTitle">false</item>
       <item name="android:windowFullscreen">true</item>
       </style>
    </resources>
    

    Refer to your custom style in your mainfest:

    <activity android:name=".MyActivity" android:theme="@style/Theme.FullScreen"/>
    

    or TODO it programatically just do

    // Remove System bar (and retain title bar)
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
    

    in code it looks like

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Window;
    import android.view.WindowManager;
    
    public class ActivityName extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Remove System bar (and retain title bar)
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
            // Set your layout
            setContentView(R.layout.main);
        }
    }