Something that should work better is to measure the screen.
Starting with API 17 there getWindowManager().getDefaultDisplay().getRealSize() , which can be compared with the size returned by getWindowManager().getDefaultDisplay().getSize() .
If you have different results, I consider it safe to say that there is a navigation bar, and if you get the same results, it is not. One thing worth paying attention to is your target SDK and supported screens, which can lead to scaling of the result of getSize() if Android believes that your application will not work on the current device without scaling.
Below API 17, you can measure the screen using getWindowManager().getDefaultDisplay().getMetrics() both landscape and portrait modes, and again, different results probably mean that there is a navigation bar.
However, if you get the same results, you don’t really know, since phones can hold the navigation bar at a shorter edge even in the landscape. It is clear that if the width or height is 4-8% less than standard sizes, such as 1280x800 , 1280x720 , 1024x600 , while the other dimension is equal, then again, there is probably a navigation bar. Do not bet on this. Too many permissions that differ too little from each other for this to work well.
ciobi May 21 '15 at 7:33 2015-05-21 07:33
source share