How Do I determine which app is causing the “Screen Overlay Detected” error?

╄→尐↘猪︶ㄣ 提交于 2020-01-01 12:01:19

问题


Let me preface this with I have already read through Android "Screen Overlay Detected" message if user is trying to grant a permission when a notification is showing and I understand exactly what the overlay problem is.

I also understand how to request it as well as how to check if my current running app has permission to draw on overlays (!Settings.canDrawOverlays(this)).

I was getting scolded for my app because every time a permission request would popup, the overlays popup would be shown and even though users gave permission for my application to draw overlays, they could never get past the permissions screen.

After some digging, the problem was that some users were running a recording app on their screen:

The problem is, this is not my app! This is AZ Screen Recorder (link) which runs as an overlay, but due to the fact that they are in my app at the time this popup appears, I am blamed for the issue.

I would like to display something to the user that they need to check for any other apps that are running something as an overlay, but I do not know how to check for this.

I can check if they are able to draw overlays in my application, but I do not know how to check for others.

My question therefore is, is there a way to programmatically check if there are currently any apps that are running an overlay at runtime and if so, can I find out the package name of said apps?

(PS, I have no qualms with the screen recorder app in question, I just wanted to link to it so that anyone can download and test if they choose)


回答1:


If you can make a test view and generate a tap event on that, then for nougat and oreo versions you can use:

view.setOnTouchListener((v, event) -> {
        if ((event.getFlags() & 0x2) != 0) {
            mPresenter.onVideoViewTapped();
            return false;
        }
        return false;
    });

Here 0x2 is the value for FLAG_WINDOW_IS_PARTIALLY_OBSCURED, which is hidden as per documentation.



来源:https://stackoverflow.com/questions/42774824/how-do-i-determine-which-app-is-causing-the-screen-overlay-detected-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!