Based in part on Pauland’s answer (in turn based on the implementation of PhoneWindowManager
), here is what I am using at the moment:
public static boolean isSystemBarOnBottom(Context ctxt) {
Resources res=ctxt.getResources();
Configuration cfg=res.getConfiguration();
DisplayMetrics dm=res.getDisplayMetrics();
boolean canMove=(dm.widthPixels != dm.heightPixels &&
cfg.smallestScreenWidthDp < 600);
return(!canMove || dm.widthPixels < dm.heightPixels);
}
This works on a Nexus 7 2012 and a Nexus 4, each running Android 5.1.
On devices that have a permanent MENU key, there is no system bar. Depending upon your use case, you may need to check for this case:
ViewConfiguration.get(ctxt).hasPermanentMenuKey()
(where ctxt
is some Context
)
Personally, I am using this to try to have a sliding panel be on the opposite axis from the system bar, as bezel swipes on the side with the system bar are a bit difficult to trigger. I would not use this, or any other algorithm (like the ones that depend upon getDecorView()
), for anything critical.