15

On some devices such as Samsung S8, navigation bar can be hide or show, that's a question in some condition. Samsung S8's navigation bar can be hide or show by click left bottom button

I didn't find straight way to determine even if in the Android sources code.

And I google some issues, such as A good solution to check for navigation bar , but it doesn't help.

Any help is very appreciated.

3
  • Do you find any answer ? I am stuck with same problem Commented Sep 25, 2017 at 10:56
  • @TUSHAR No, I still cannot find a good solution. I think Android should make it standardized. Commented Sep 27, 2017 at 2:54
  • 3
    With more and more full screen phones appears, not just Samsung Galaxy S8/Note8, but Xiaomi, Huawei, etc. If The Android Sources don't make it standardized ASAP, this can become a serious problem. Commented Nov 13, 2017 at 7:32

2 Answers 2

5

First, credit the original author: https://www.jianshu.com/p/ddfbabd614b6

For the Samsung phones (i.e, S8, S9, etc) you can detect if the navigation bar is showing via listening to a Samsung event.

private static final String SAMSUNG_NAVIGATION_EVENT = "navigationbar_hide_bar_enabled";

Then just listen to this event, and do your thing:

private void checkNavigationBar() {
    if (isSamsungVersionNougat()) { // check if Samsung phones
        // detect navigation bar
        try {
            // there are navigation bar
            if (Settings.Global.getInt(activity.getContentResolver(), SAMSUNG_NAVIGATION_EVENT) == 0) {
                // Your code
                // example: galleryViewModel.navigationBarHeight.set(getNavigationBarHeight());
            } else { // there are no navigation bar
                // Your code
                // example: galleryViewModel.navigationBarHeight.set(0);
            }
        } catch (Exception ignored) {
        }
        barHideEnableObserver = new BarHideEnableObserver(new Handler());
        activity.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(SAMSUNG_NAVIGATION_EVENT),
                true, barHideEnableObserver);
    } else {
        galleryViewModel.navigationBarHeight.set(getNavigationBarHeight());
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Worked for me, this was the only solution we had for finding full screen window height on on Samsung phones that had the collapsible bar
any idea about how to detect this on devices from other manufacturer?
for xamarin developers with same issue check this
okay, this is where it is came from: jianshu.com/p/ddfbabd614b6
0

Use this method, worked for me. Make sure the view has been rendered first to make sure that getHeight() doesn't return 0. Also make sure that the rootView you are using is meant to take up the whole screen.

public static boolean hasNavBar (Activity activity, View rootView) {
    if (activity == null || rootView == null)
        return true;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        return true;

    Display d = activity.getWindowManager().getDefaultDisplay();
    DisplayMetrics realDisplayMetrics = new DisplayMetrics();
    d.getRealMetrics(realDisplayMetrics);

    int viewHeight = rootView.getHeight();
    if (viewHeight == 0)
        return true;

    int realHeight = realDisplayMetrics.heightPixels;
    return realHeight != viewHeight;
}

1 Comment

It does not work when this flag is set on activity's window: WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

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.