1

I am creating an Android app for blind users. One usability issue is that their fingers tend to touch the Back button in the Navigation Bar, and they suddenly find themselves out of the app.

In Android 4.4 KitKat and later, I can use...

  getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

... to hide the Navigation bar. (On earlier versions, I can suggest that users put a thick elastic band around their phone to hide the Navigation bar.)

I would like to include the call above in an app compatible with API 2.2 Froyo, without provoking an error, so that the elastic band is not necessary on more recent phones.

I've looked at this question but I'm not quite sure how to apply the suggested answers to the MainActivity method in a barebones Hello World project.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // etc
    }
}

EDIT
Here is my modified code, which now works for me:

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Hide:
        // * the topmost bar with the time, date, charge, carrier and other information
        // * the bar than shows the app logo and title

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            requestWindowFeature(Window.FEATURE_NO_TITLE);

        } else {
            // On API 19 KitKat 4.4. also hide
            // * the Navigation bar that will appear at bottom or right of screen.
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    // MORE CODE
}
Community
  • 1
  • 1
James Newton
  • 6,623
  • 8
  • 49
  • 113
  • 4
    The right answers on that questions are the ones with the simple `if` statement, such as [this answer](http://stackoverflow.com/a/7410282/115145). The accepted answer is very old and is no longer really relevant. – CommonsWare Jan 13 '15 at 23:16
  • Your code looks good. What is your question? – Hartok Jan 14 '15 at 01:27

0 Answers0