2

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();
                }
            }
        }
    }
}
herman brain
  • 285
  • 1
  • 4
  • 6

2 Answers2

4

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);
avepr
  • 1,865
  • 14
  • 16
2

Simple solution, just add android:theme=”@android:style/Theme.NoTitleBar.Fullscreen” to your manifest, for example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.vogella.android.temperature"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Convert"
                  android:label="@string/app_name"
                   android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest>
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104
ramdroid
  • 6,738
  • 1
  • 16
  • 14
  • i have set the full screen theme. but i when i call public void onAttachedToWindow() { if (!mInPreviewBoolean){ this.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);//for capture the home key } super.onAttachedToWindow(); } then the status bar will become visible,my implement is a lock screen activity, so want activity is full screen and the status bar is invisible or disable. I have add permission android.permission.EXPAND_STATUS_BAR, then i can access statusbar.collapse(), but even i have add android.permission.STA – herman brain Feb 08 '12 at 02:12
  • This still allows access to the notification when you swipe down from the top bezel. – Archimedes Trajano Nov 03 '13 at 05:23