How to detect full screen gesture mode in android 10

Viewed 6366

In Android 10, users can enable full screen gesture mode. I want to detect whether the device in full screen gesture mode or not. I can't find anything in documentation. How to do it programmatically at run time?

Java or kotlin language answer is OK.

Any official API or workaround...

3 Answers

You can use below code to check gesture or navigation mode

    public static int isEdgeToEdgeEnabled(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
        if (resourceId > 0) {
            return resources.getInteger(resourceId);
        }
        return 0;
    }

The value that returned by isEdgeToEdgeEnabled function will follow below:

  • 0 : Navigation is displaying with 3 buttons

  • 1 : Navigation is displaying with 2 button(Android P navigation mode)

  • 2 : Full screen gesture(Gesture on android Q)

I found this article really useful in explaining what WindowInsets are and how to use them.

Basically I check if the left gesture inset is greater than 0, and if it is then the system is using gesture type navigation. Left and right gesture insets have to be greater than 0 in gesture type navigation because you swipe from the right or left to go back.

int gestureLeft = 0;

if (Build.VERSION.SDK_INT >= 29) {
    gestureLeft = this.getWindow().getDecorView().getRootWindowInsets().getSystemGestureInsets().left;
}

if (gestureLeft == 0) {
    // Doesn't use gesture type navigation
} else {
    // Uses gesture type navigation
}

Obviously, the window has to be rendered for this to work. You can add it inside an OnApplyWindowInsetsListener if you want this to run as soon as the window is rendered.

Note: I tried using getSystemGestureInsets().bottom, but it returned a non-zero value even when I wasn't using gesture type navigation.

Related