I have just encountered a bug while using most of the solutions above that suggest adding a fixed number.
S4 is has a high dpi which resulted in the navigation bar's height being 100px thus my app thinking that the keyboard is open all the time.
So with all the new high res phones being released i believe using a hard coded value is not a good idea for long term.
A better approach that i found after some testing on various screens and devices was to use percentage. Get the difference between decorView and ur app content and afterwards check what is the percentage of that difference. From the stats that i got, most nav bar(regardless of the size, resolution etc..) will take between 3% to 5% of the screen. Where as if the keyboard is open it was taking between 47% to 55% of the screen.
As a conclusion my solution was to check if the diff is more than 10% then i assume its a keyboard open.