Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android detect Samsung Galaxy S8 navigation bar hide or show programmatically

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.

like image 993
Smiles Avatar asked Sep 08 '17 01:09

Smiles


People also ask

How do I Auto Hide navigation bar on Samsung?

It's a nice mixture of Android 9 Pie and Android 10 gestures. Go through the steps below to make changes. Step 1: Open the Settings app on your Samsung device. Step 2: Navigate to the Display > Navigation Bar > Full screen gestures > More options > Swipe from bottom.

How do I Auto Hide navigation bar?

Using the Show and hide button at the left side of the navigation bar, you can set the navigation bar to be hidden or pinned on the screen when you use apps or features. The navigation bar is pinned by default.

How can the customer hide the navigation bar on their S8 device while watching a movie?

Go to Settings > Display > Navigation Bar. Tap the toggle beside Show and hide button to switch it to the on position. If you don't see this option, check for any available software updates. The update might not be out all carrier-specific Galaxy S8 phones yet.


1 Answers

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());
    }
}
like image 189
Haomin Avatar answered Oct 18 '22 23:10

Haomin