0

Now before anyone marks question as a duplicate, please read the question carefully. I have tried each and every current answer on Stack Overflow.

In general, I want to know how to detect if there exists any soft Navigation Bar at the bottom of the screen on the user's device.

Now,

1) I have seen an answer where people check the maximum screen size, see which app/activity is being displayed and then, depending upon the result, decide whether there is a soft Nav Bar not. This will not be reliable for devices with a notch.

2) I'm not interested to know if there is a hardware Nav Bar or not. A Soft Nav Bar is a must because:

a. In my actual device, there are no hardware Nav Bars and no soft Nav Bar either. Several phone nowadays uses gestures to navigate.

b. But in my emulator, there are nav bar. There are soft Nav Bars.

To hide them I use this code:

int uiOptionsForDevicesWithoutNavBar = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        |  View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptionsForDevicesWithoutNavBar);

Now, this works like a charm. Waalaa, Nav Bars are hidden. But here comes the problem on my actual phone. It uses Gestures. On my first swipe for Back, the notification bar appears and then on the next immediate swipe for Back, the required back action takes place.

But if I do this:

int uiOptionsForDevicesWithoutNavBar = View.SYSTEM_UI_FLAG_FULLSCREEN
        |  View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptionsForDevicesWithoutNavBar);

Then it works properly on my physical device, but the Nav Bar doesn't get hidden on the emulator, which is obvious because the main flag that hides it is not there.

So I want to run different flags for different types of phones depending upon whether the device has on-screen Soft Nav Bars or not.

Hence, I'd like to know how to detect if there are on screen soft Nav Bars or not.

Also, if there is a better way to do it, please help me.

1
  • Come on, seriously.... is there no solution to it? I have seen tons of game that can do it smoothly without any problem....... T_T........... Commented Mar 5, 2020 at 16:15

1 Answer 1

1
public boolean hasNavigationBar(Resources resources) {
        int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
        return id > 0 && resources.getBoolean(id);
    }

This method will read from the Android system the value config_showNavigationBar boolean. Many OEMs use this value when hiding or showing the navigation bar like Samsung.

Note: many third party apps are hiding the navigation bar via a tricky ADB command , I still didn't find a way to detect this , please see this question

Sign up to request clarification or add additional context in comments.

1 Comment

a verbal explanation with the answer is often very helpful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.