本文介绍了有没有一种方法来检查状态栏的知名度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,应该定期检查可见状态栏,在一些顶级的活动(或没有)在全屏模式下的服务。这可能吗?

I have a service that should check periodically visibility of status bar, when some top activity is (or not) in fullscreen mode.Is it possible?

推荐答案

最后,我已经发现了如何检查,如果状态栏是可见或不可见。它的某种形式的黑客攻击,但它为我工作。我在服务创建的方法:

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;
                }
            }
        });

    }

其中的宽度和高度我们在全球的屏幕尺寸;在这里,我只是比较不可见的辅助窗口的高度为屏幕高度,科学决策,如果状态栏是可见的。而且不要忘了删除helperWnd在你的服务的onDestroy。

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.

这篇关于有没有一种方法来检查状态栏的知名度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:46