`setSystemGestureExclusionRects` does not work for many real devices

Viewed 23

I need to use setSystemGestureExclusionRects to prevent Android's "swipe from edge of device to trigger back navigation", for my app's painter-like feature. However, though it works perfectly on android simulator, it does not work for many real devices.

Reproducible sample: https://github.com/fzyzcjy/android_gesture_exclusion_example

Core code(https://github.com/fzyzcjy/android_gesture_exclusion_example/blob/master/app/src/main/java/com/example/myapplication/MainActivity.kt):

    binding.root.doOnNextLayout {
        val exclusions = listOf(Rect(0, it.bottom - 200, 100, it.bottom))
        ViewCompat.setSystemGestureExclusionRects(binding.root, exclusions)
    }

Expected behavior: When dragging horizontally from left to right near the left-bottom of the left edge of the device (i.e. the exclusions region in the code), android system should not trigger back navigation.

Experiments:

  • Android simulator, android 30: Expected behavior
  • Android simulator, android 29: Expected behavior
  • Real Redmi device, android 29: Unexpected behavior (seems the setSystemGestureExclusionRects does not work at all)
  • Real Honor device, android 29: Unexpected behavior (same as above)
0 Answers
Related