以编程方式检测Android屏幕覆盖 [英] Detecting Android screen overlays programmatically

查看:170
本文介绍了以编程方式检测Android屏幕覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序是否可以:

  1. 检查其上方是否有屏幕叠加层,并且
  2. 弄清楚覆盖层的包装名称是什么?

我知道Android M及更高版本可以在权限页面中检测到屏幕覆盖,并且每当检测到屏幕覆盖时都可以拒绝更改权限,但是开发人员能够在应用程序层中实现相同的目的吗?

I know Android M and above is able to detect screen overlays when in the permissions page and deny permission changes whenever it detects screen overlays, but are developers able to achieve the same things in the app layer?

推荐答案

您可以通过检查 MotionEvent.FLAG_WINDOW_IS_OBSCURED 标志> View s.

You can detect overlays by checking for the MotionEvent.FLAG_WINDOW_IS_OBSCURED flag when the user touches one of your Views.

final View.OnTouchListener filterTouchListener = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // Filter obscured touches by consuming them.
        if ((event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                Toast.makeText(v.getContext(), "Overlay detected", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
        return false;
    }
};

yourButton.setOnTouchListener(filterTouchListener);

来源:但是,我认为无法检测出哪个应用拥有重叠广告.

However, I don't think it's possible to detect which app owns the overlay.

这篇关于以编程方式检测Android屏幕覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆