Is there a way to check the visibility of the status bar?
Finally I have discovered how to check if statusbar is visible or not. Its some kind of hack, but it works for me. I created that method in my Service:
private void createHelperWnd() {
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams p = new WindowManager.LayoutParams();
p.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
p.gravity = Gravity.RIGHT | Gravity.TOP;
p.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
p.width = 1;
p.height = LayoutParams.MATCH_PARENT;
p.format = PixelFormat.TRANSPARENT;
helperWnd = new View(this); //View helperWnd;
wm.addView(helperWnd, p);
final ViewTreeObserver vto = helperWnd.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (heightS == helperWnd.getHeight()) {
isFullScreen = true;
} else {
isFullScreen = false;
}
}
});
}
where widthS and heightS our global screen size; Here I just compared invisible helper window height to screen height and make decision if status bar is visible. And do not forget to remove helperWnd in onDestroy of your Service.
public boolean isStatusBarVisible() {
Rect rectangle = new Rect();
Window window = getActivity().getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = rectangle.top;
return statusBarHeight != 0;
}
hello and if you try this code that provides android as good practice
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
I leave the link of the documentation: https://developer.android.com/training/system-ui/visibility#java