Is there a way in Android to detect if the software (a.k.a. \"soft\") keyboard is visible on screen?
You can refer to this answer - https://stackoverflow.com/a/24105062/3629912
It worked for me everytime.
adb shell dumpsys window InputMethod | grep "mHasSurface"
It will return true, if software keyboard is visible.