I am trying to use the WindowInsetsCompat APIs to check if the soft keyboard is visible or not.
One solution that I found is
val insets = ViewCompat.getRootWindowInsets(view)
val isKeyboardVisible = insets?.isVisible(Type.ime())
But this getRootWindowInsets(view)
function only works for API >= 23. For lower APIs, it always returns null
.
As per the android release notes,
The WindowInsetsCompat APIs have been updated to those in the platform in Android 11. This includes the new ime() inset type, which allows checking the visibility and size of the on-screen keyboard.
Some caveats about the ime() type, it works very reliably on API 23+ when your Activity is using the adjustResize window soft input mode. If you’re instead using the adjustPan mode, it should work reliably back to API 14.
It says that ime() type should work reliably back to API 14 when using adjustPan. I am working with a minSdk of 19 and am having trouble figuring out what functions to use to check ime visibility.
Can anybody help me with this? Thanks in advance.