我有一项服务应定期查看状态栏的可见性,当全屏模式下某些顶级活动是(或不是)时.
可能吗?
可能吗?
解决方法
最后,我发现了如何检查状态栏是否可见.它有点像黑客,但它对我有用.我在我的服务中创建了该方法:
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; } } }); }
其中widthS和heightS是我们的全局屏幕尺寸;在这里,我只是将隐形辅助窗口高度与屏幕高度进行比较,并确定状态栏是否可见.并且不要忘记在服务的onDestroy中删除helperWnd.