5

I have been using view.rootWindowInsets.stableInsetTop and bottom to get the height of the status and navigation bars, however this is now deprecated and the docs advise to use rootWindowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()).top

So I have the below code now

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
        view.rootWindowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()).top
    else
        @Suppress("DEPRECATION")
        view.rootWindowInsets.stableInsetTop

This works find on API 24 and API 30 emulators, however on Galaxy S20 FE running API 29 (Andorid 10) this doesn't work.

I get the following error

Accessing hidden method Landroid/view/WindowInsets$Type;->systemBars()I (blacklist, linking, denied)
2021-01-17 01:45:18.348 23013-23013/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: app.test.debug, PID: 23013
    java.lang.NoSuchMethodError: No static method systemBars()I in class Landroid/view/WindowInsets$Type; or its super classes (declaration of 'android.view.WindowInsets$Type' appears in /system/framework/framework.jar!classes3.dex)

Evidently systemBars() was graylisted in API 29 and is blacklisted in API 30. (Device still throws despite running API 29)

So what should I use to get this information that works on API levels 24 and up?

I can use view.rootWindowInsets.stableInsetTop as above, but I'd prefer to use a non-deprecated API.

Madushan
  • 6,977
  • 31
  • 79
  • I faced the same issue, do you find any solution ?? – Fabien Fontaine Mar 05 '21 at 13:15
  • unfortunately no.. `view.rootWindowInsets` seems to work ok despite being deprecated. I noticed many Google apps still just change the color of system bars instead of going edge to edge as well. See here for brief moment Leland Richardson shows how to make status bar translucent https://youtu.be/fwn7olJOc70?t=499 He says its just too complicated today, and he decided to jsut copy the code off of Stackoverflow. Also that code is filled with deprecated APIs. (it is a demo project though. Not a production app.) – Madushan Mar 07 '21 at 10:00
  • did you try the Compat Method? WindowInsetsCompat.Type.systemBars()).top – Rahul Pawar Oct 24 '21 at 19:53
  • This used to crash on samsung (Android 10) as well, but seems to work now (upgraded to Android 11). Reluctant to use as it causes the uncatchable exception for devices that aren't yet upgraded. – Madushan Oct 24 '21 at 23:22

0 Answers0