1
 private void hideSystemUI() {

 View decorView = getWindow().getDecorView();

 int uiOptions = 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;

  decorView.setSystemUiVisibility(uiOptions);
   }

and also:

@Override

public void onWindowFocusChanged(boolean hasFocus)
{

 super.onWindowFocusChanged(hasFocus);

  View decorView = getWindow().getDecorView();

  decorView.setOnSystemUiVisibilityChangeListener( 
        newView.OnSystemUiVisibilityChangeListener() {

         @Override

         public void onSystemUiVisibilityChange(int i) {

            if (i == View.VISIBLE){
                hideSystemUI();
            }
            else {
                hideSystemUI();
            }
        }
    });

wrote the hidesystemUI() code in onCreate() and onResume() also, including with decorView.setOnSystemUiVisibilityChangeListener(). So i have to block it. Once i swipe at the top, it is coming and going back ( like a blink). But i have to block it. Once we swipe at the top it should not appear. help me out of this.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • check this , https://stackoverflow.com/questions/29969086/how-to-disable-status-bar-click-and-pull-down-in-android – hemen Dec 19 '17 at 07:30

1 Answers1

0

If you do not want it to blink, you may delay hiding. For example, you can give it a 2 seconds delay by Handler.postDelayed().

private void hideSystemUI() {
    final int uiOptions = 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;

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            getWindow().getDecorView().setSystemUiVisibility(uiOptions);
        }
    }, 2000); //2 seconds delay
}

If you are always calling this on the main thread, you can simply call new Handler() to return a Handler on the main thread. Otherwise, you will need to call new Handler(Looper.getMainLooper()).

Siu
  • 1,422
  • 1
  • 12
  • 17
  • Sorry Siu, this is not the exact solution i'm looking for. But i understood that blocking the system UI permanently is not possible and that is possible only for System apps. So i found another way for that--Thank you. – Govindu Satish Jan 05 '18 at 06:56
  • No problem! I thought you just don't like it blinking. Glad you find the solution! :) – Siu Jan 05 '18 at 06:59
  • Do you know how to retrieve name, mobile number and photo from favourite contacts. – Govindu Satish Jan 05 '18 at 07:02
  • [Here](https://developer.android.com/training/contacts-provider/retrieve-names.html) is the official tutorial on how to get contacts. You may refer to [this answer](https://stackoverflow.com/a/18892586/3061187) for getting only favourite contacts. Notice the query uses ContactsContract.Contacts.STARRED=1 . You may check if the contact has phone number by adding ContactsContract.Contacts.HAS_PHONE_NUMBER into the query's projection field. You can then get phone numbers by the ID as shown [here](https://stackoverflow.com/a/11219123/3061187). – Siu Jan 05 '18 at 07:17
  • [link](https://stackoverflow.com/questions/48108804/how-to-retrieve-name-mobile-number-and-display-photo-from-favourite-starred-con?noredirect=1#comment83192768_48108804) ... once check the link plz, my updated code and question. – Govindu Satish Jan 05 '18 at 07:37
  • Had a quick look. Not sure why you using GROUP_PROJECTION. I guess if what you need are favourited contacts' phone number, name, photo, the projection should be `ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER, ContactsContract.Contacts.PHOTO_URI`. Check out [this page](https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html) to see what you can use. And of course, keep the "starred=1" selection criteria. – Siu Jan 05 '18 at 08:34
  • Thanks a lot Siu... Works perfect.. you saved my day.. :) – Govindu Satish Jan 05 '18 at 09:26