Android Android detects Samsung Galaxy S8 navigation bar hide or show programmatically

On some devices, such as Samsung S8, the navigation bar can be hidden or show that the question is in some condition. The Samsung S8 navigation bar can be hidden or shown by pressing the lower left button

I did not find a direct way to determine if there is Android in the source code.

And I google some problems, such as a Good solution for checking the navigation bar , but it does not help.

Any help is greatly appreciated.

+14
source share
2 answers

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

Samsung (, S8, S9 ..) , , Samsung.

private static final String SAMSUNG_NAVIGATION_EVENT = "navigationbar_hide_bar_enabled";

:

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());
    }
}
+3

, . , , , getHeight() 0. , rootView, , .

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;
}
0

Source: https://habr.com/ru/post/1685271/


All Articles