Search code examples
androidpermissionsstatusbar

How to disable statusbar in android?


i want disable statusbar in activity, i have use below code, it happen SecurityException, StatusBarManagerService: Neither user 10049 nor current process has android.permission.STATUS_BAR. I have add <uses-permission android:name="android.permission.STATUS_BAR">, but it's not works? Anyone know how to resolve this problem? Thanks

mStatusBar = getSystemService("statusbar");

if (mStatusBar != null){
    Log.v("statusbar", "get status bar service "+mStatusBar.getClass());
    Method[] arrayOfMethods;
    Method localMethod;
    arrayOfMethods = mStatusBar.getClass().getMethods();
    for (int i = 0; i < arrayOfMethods.length; i++){
        localMethod = arrayOfMethods[i];
        Log.v("statusbar", "find status bar method "+localMethod);
        if (localMethod.getName().equalsIgnoreCase("collapse")){
//                    mStatusBarCollapseMethod = localMethod;
            } else if (localMethod.getName().equals("disable")){
                try {
                    Log.v("statusbar", "invoke "+mStatusBar+"."+localMethod.getName()+"(1)");
                    localMethod.invoke(mStatusBar, 1);
                    Log.v("statusbar", "disable statusbar");
                } catch (Exception e) {
                    Log.v("statusbar", "disable statusbar excption:"+e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
}

Solution

  • IF you need to disable the status bar from your java code, then you can do this:

    Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);