0

If the device is running ICS I want to hide the status bar with:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

But the View.SYSTEM_UI_FLAG_LOW_PROFILE parameter is defined in Android API 14.

My manifest is now:

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14" />

and

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

But then it crashes with:

java.lang.NoSuchMethodError: android.view.View.setSystemUiVisibility

What can I do to call this method and keep it compatible with Android devices with a lower api level?

TZHX
  • 5,291
  • 15
  • 47
  • 56
Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
  • Please check the following links: http://stackoverflow.com/questions/8273186/android-show-hide-status-bar-power-bar and http://stackoverflow.com/questions/5431365/how-to-hide-status-bar-in-android – Blehi May 04 '12 at 12:19
  • 1
    check the api level and call the method only if api >= 14 and on the lower api request full screen. supporting api 4 isn't really necessary imho – WarrenFaith May 04 '12 at 12:19
  • Thanks WarrenFaith, didn't thought of that. [Build.VERSION.SDK_INT > 11] works great! – Ion Aalbers May 04 '12 at 12:27
  • Note that it "works great" for Android 2.0 and higher. On Android 1.x, you need to do a bit more to avoid a `VerifyError`. – CommonsWare May 04 '12 at 12:29
  • Lol, yeah. But minSdkVersion is at 4 ;-) – Ion Aalbers May 04 '12 at 12:31

1 Answers1

2

You can get the version by using

int SDK_INT = android.os.Build.VERSION.SDK_INT;

and u can check the version before set the parameter

if(SDK_INT >= 11 && SDK_INT < 14) {
        getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
    }else if(SDK_INT >= 14){
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    }
Krishna Prasad
  • 693
  • 1
  • 6
  • 19
  • View.STATUS_BAR_HIDDEN is API 11. You will still get a crash on API 10 and lower – Ion Aalbers May 04 '12 at 13:03
  • It is of best practice to do import static android.os.Build.VERSION.SDK_INT; rather then int SDK_INT = android.os.Build.VERSION.SDK_INT; – Pierre-Antoine Sep 11 '12 at 20:36
  • 1
    How would this avoid `java.lang.NoSuchMethodError: android.view.View.setSystemUiVisibility`? You are still loading code with this method, on an API level that doesn't have this method. Likewise the field `STATUS_BAR_HIDDEN`. – Sean Owen Sep 25 '12 at 11:29
  • You can also use the [Build.VERSION_CODES](http://developer.android.com/reference/android/os/Build.VERSION_CODES.html) instead of the hard coded SDK integers if you prefer. – robd Apr 19 '14 at 10:39