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.