1

In Android a user can decide between two navigation modes:

  1. Gesture navigation > no system navigation bar will be shown, and any back swipe will trigger onWillPop
  2. Button navigation (with 2/3 buttons) > the system navigation bar will be shown, and only the back button will trigger onWillPop (there is no longer a back swipe detection)

In my application, whenever one of those two methods is used to 'go back', I'm trying to determine where the onWillPop callback came from: was it a back button press what triggered it, or was it a back swipe? I need this info in order to allow the user to perform certain actions in the app (the details are irrelevant to the question, but I basically need to decide whether to open a drawer or trigger a webview back navigation).

I haven't been able to obtain this information directly: is there a direct way to ascertain whether the back navigation action came from?

My second option was to try to get the status of the system navigation bar (shown/hidden) whenever onWillPop is called, so that I can guess where it came from. But I can't locate this information either. I saw I can get the kBottomNavigationBarHeight, which is constant independent of the bar's status, or the bottom padding with MediaQuery, which doesn't seem to be realiable and probably depends on the device and the size of the SafeArea.

Is there a way to get the current status of the navigation bar, or the user's preferences?

Manu
  • 141
  • 2
  • 13
  • U could write a MethodCannel and call the function here to check if the system navigation bar is available https://stackoverflow.com/a/32698387/5812524 or a dirty hack: check for a horizontal gesture and set a boolean isBackGesture and check this variable inside your onWillPop – Ozan Taskiran Oct 16 '22 at 23:24

1 Answers1

0

This method detects if the gesture navigation mode is enabled.

public static boolean isGestureNavigationMode(ContentResolver content) {
    return Settings.Secure.getInt(content, "navigation_mode", 0) == 2;
}

You can know if the user is using the gesture navigation mode simply by calling the method on a Boolean object. Example:

boolean gestures = isGestureNavigationMode(this.getContentResolver());

If the Boolean gestures is true the user is using navigation mode otherwise no.

gcantoni
  • 727
  • 6
  • 13
  • Thanks, this seems to be reasonable as per @Ozan comment. Nevertheless, the platform is Flutter so I was looking for a better integration in the framwork. – Manu Oct 18 '22 at 18:01